35 lines
1.0 KiB
Python
Executable File
35 lines
1.0 KiB
Python
Executable File
#!/usr/bin/env python3.11
|
|
from collections.abc import Iterable
|
|
from common import *
|
|
|
|
|
|
def all_equals(points: list[Point]) -> bool:
|
|
first = points[0]
|
|
logging.debug(f"testing {points} with value {first}")
|
|
return all(map(lambda x: x == first, points))
|
|
|
|
|
|
def farthest_length(labyrinth: Labyrinth) -> int:
|
|
length = 1
|
|
current_vectors = list(
|
|
((labyrinth.start, point) for point in labyrinth.first_points)
|
|
)
|
|
logging.debug(f"first vectors: {current_vectors}")
|
|
current_points = list(vector[1] for vector in current_vectors)
|
|
logging.debug(current_points)
|
|
while not all_equals(current_points):
|
|
new_vectors = []
|
|
new_points = []
|
|
for vector in current_vectors:
|
|
new_vector = (vector[1], movement(vector[1], vector[0], labyrinth))
|
|
new_vectors.append(new_vector)
|
|
new_points.append(new_vector[1])
|
|
current_vectors = new_vectors
|
|
current_points = new_points
|
|
length += 1
|
|
return length
|
|
|
|
|
|
if __name__ == "__main__":
|
|
print(farthest_length(parse("input.txt")))
|