from itertools import product, count from functools import reduce from operator import or_, add lines = open("input").readlines() width, height = len(lines[0]) - 3, len(lines) - 2 start = (lines[0].index(".") - 1, -1) end = (lines[-1].index(".") - 1, height) spaces = set(product(range(width), range(height))) | {start, end} dirs = ((1, 0), (-1, 0), (0, 1), (0, -1), (0, 0)) arrows = ">