from copy import deepcopy from util import get_input input = get_input("25.input") grid = [[c for c in line] for line in input] grid_size = (len(grid[0]), len(grid)) def print_grid(grid): for line in grid: print("".join(line)) print("-" * 20) def step(grid): moved = False new_grid = deepcopy(grid) for y, line in enumerate(grid): for x, c in enumerate(line): if c == '>' and grid[y][(x + 1) % grid_size[0]] == '.': moved = True new_grid[y][x] = '.' new_grid[y][(x + 1) % grid_size[0]] = '>' new_new_grid = deepcopy(new_grid) for y, line in enumerate(new_grid): for x, c in enumerate(line): if c == 'v' and new_grid[(y + 1) % grid_size[1]][x] == '.': moved = True new_new_grid[y][x] = '.' new_new_grid[(y + 1) % grid_size[1]][x] = 'v' return (moved, new_new_grid) print_grid(grid) i = 0 while True: i += 1 moved, grid = step(grid) if not moved: break #print_grid(grid) print(i) #print_grid(grid) print("Part 1:", i)