Skip to content
Snippets Groups Projects
Commit 4aea0ff1 authored by Rick van Hoef's avatar Rick van Hoef
Browse files

start isomorphic compare

parent c6580148
No related tags found
No related merge requests found
......@@ -100,3 +100,49 @@ class Cinema:
amount += 1
return amount
def isomorphic_compare(self, other: Cinema) -> bool:
# size of the grid
size = height * width
# the four possible directions in the other cinema
# we will also find isomorphisms that are shifted versions of this cinema
# in all directions
start, north, south, west, east = 0, 0, 0, 0, 0
# skipping empty seats in every direction, including the current cinema
while self.seats[start] != SeatStatus.Available:
start = start + 1
while other.seats[north] != SeatStatus.Available:
north = north + 1
while other.seats[size - south - 1] != SeatStatus.Available:
south = south + 1
# I hate this indexing, but it will do for now
while (
other.seats[width * (east // width) + width - east % width - 1]
!= SeatStatus.Available
):
east = east + 1
while (
other.seats[size - width * (west // width) - width + (west % width)]
!= SeatStatus.Available
):
west = west + 1
# actual compare (just once cause I'm done for today)
for i in range(size - start):
if self.seats[start] == SeatStatus.Available:
if other.seats[i + north] != SeatStatus.Available:
break
else:
if other.seats[i + north] == SeatStatus.Available:
break
if i == size - start:
# actually still have to check if the rest is empty, but I'm done for today
return True
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment