from lib import * EXAMPLE = """ ........... .....###.#. .###.##..#. ..#.#...#.. ....#.#.... .##..S####. .##..#...#. .......##.. .##.#.####. .##..##.##. ........... """ def solve(i: Input, second=False): res = 0 g = i.grid2() s = g.find('S')[0] g[s] = 'O' # steps = 64 steps = 26501365 seen = set() for i in range(steps): os = tuple(g.find('O')) if os in seen: seen.add(os) print(f"SEEN {i}") break for o in os: g[o] = '.' for o in os: for nb in g.neighbors_ort(o): if not g[nb] == "#": g[nb] = 'O' return len(g.find('O')) def main(): DAY_INPUT = "i21.txt" print("Example 1:", solve(Input(EXAMPLE))) print("Solution 1:", solve(Input(DAY_INPUT))) return print("Example 2:", solve(Input(EXAMPLE), True)) return print("Solution 2:", solve(Input(DAY_INPUT), True)) return if __name__ == "__main__": main()