-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathday25.py
More file actions
38 lines (32 loc) · 950 Bytes
/
day25.py
File metadata and controls
38 lines (32 loc) · 950 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from aoc import *
def turn(grid):
new_grid = [['.' for _ in range(w)] for _ in range(h)]
moved = False
for y, line in enumerate(grid):
for x, c in enumerate(line):
if c == '>':
if line[(x+1)%w] == '.':
moved = True
new_grid[y][(x+1)%w] = '>'
else:
new_grid[y][x] = '>'
for y, line in enumerate(grid):
for x, c in enumerate(line):
if c == 'v':
if grid[(y+1)%h][x] != 'v' and new_grid[(y+1)%h][x] == '.':
moved = True
new_grid[(y+1)%h][x] = 'v'
else:
new_grid[y][x] = 'v'
return new_grid, moved
def solve(grid):
moved = True
cnt = 0
while moved:
cnt += 1
grid, moved = turn(grid)
return cnt
data = read_input(25, list)
w = len(data[0])
h = len(data)
print(solve(data))