-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday25.krk
46 lines (41 loc) · 1.07 KB
/
day25.krk
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
39
40
41
42
43
44
45
46
#!/usr/bin/env kuroko
'''
Day 25
'''
import fileio
import kuroko
let data
with fileio.open(kuroko.argv[1] if len(kuroko.argv) > 1 else kuroko.argv[0].replace('.krk','.txt'),'r') as f:
data = f.readlines()
let lines = [[x for x in line.strip()] for line in data]
let height = len(lines)
let width = len(lines[0])
def iterate_once():
let movers = set()
for y in range(height):
for x in range(width):
if lines[y][x] == '>':
if lines[y][(x+1)%width] == '.':
movers.add((y,x))
let c = len(movers)
for y,x in movers:
lines[y][x] = '.'
lines[y][(x+1)%width] = '>'
movers.clear()
for y in range(height):
for x in range(width):
if lines[y][x] == 'v':
if lines[(y+1)%height][x] == '.':
movers.add((y,x))
if c == 0 and len(movers) == 0:
return True
for y,x in movers:
lines[y][x] = '.'
lines[(y+1)%height][x] = 'v'
return False
let i = 1
while True:
if iterate_once():
break
i += 1
print(i)