-
Notifications
You must be signed in to change notification settings - Fork 0
/
part1.py
38 lines (30 loc) · 967 Bytes
/
part1.py
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
def simulate(sea):
new_sea = [['.'] * WIDTH for _ in range(HIEGHT)]
for y in range(HIEGHT):
for x in range(WIDTH):
if sea[y][x] == '>':
next_x = (x + 1) % WIDTH
if sea[y][next_x] == '.':
new_sea[y][next_x] = '>'
else:
new_sea[y][x] = '>'
for y in range(HIEGHT):
for x in range(WIDTH):
if sea[y][x] == 'v':
next_y = (y + 1) % HIEGHT
if sea[next_y][x] != 'v' and new_sea[next_y][x] == '.':
new_sea[next_y][x] = 'v'
else:
new_sea[y][x] = 'v'
return new_sea
with open('input.txt') as file:
sea = [list(line) for line in filter(None, map(str.strip, file))]
WIDTH, HIEGHT = len(sea[0]), len(sea)
steps = 0
while True:
steps += 1
new_sea = simulate(sea)
if new_sea == sea:
break
sea = new_sea
print(steps)