def part_a(data): seen = set() grid = ZGrid(data) while True: k = tuple(grid.items()) if k in seen: return sum(2**i for i, glyph in enumerate(grid.values()) if glyph == "#") seen.add(k) evolve_a(grid)
grid = ZGrid() x0 = 0 for y in range(50): on = False for x in range(x0, 50): z = x + y*1j val = grid[z] = beam(z) if not on and val: on = True x0 = x if x0: m = y / x0 if on and not val: break grid.draw() print("part a", sum(grid.values())) def left_edge_of_beam(y, gradient): x = int(y / gradient) z = x + y*1j if beam(z): while beam(z - 1): z -= 1 else: while not beam(z + 1): z += 1 z += 1 assert beam(z) and not beam(z - 1) return z