-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday25a.py
65 lines (44 loc) · 1.2 KB
/
day25a.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from copy import deepcopy
f = open("input.txt", "r")
#f = open("testInput.txt", "r")
dat = f.read().splitlines()
dat = [list(d) for d in dat]
prev = deepcopy(dat)
m,n = len(dat), len(dat[0])
count = 1
def p(m):
for r in m:
print(r)
print()
#p(dat)
while True:
new = deepcopy(prev)
moved = set()
# move all east (left->right)
for i in range(len(dat)):
for j in range(len(dat[0])):
if prev[i][j] == ">" and (i,j) not in moved:
if prev[i][(j+1)%n] == ".":
new[i][(j+1)%n] = ">"
new[i][j] = "."
moved.add((i,(j+1)%n))
#print("dfas")
ref = deepcopy(new)
moved = set()
# move all south (top->down)
for i in range(len(dat)):
for j in range(len(dat[0])):
if ref[i][j] == "v" and (i,j) not in moved:
if ref[(i+1)%m][j] == ".":
new[(i+1)%m][j] = "v"
new[i][j] = "."
moved.add(((i+1)%m, j))
#print("dfas")
if prev == new:
break
prev = deepcopy(new)
#print(count)
#p(prev)
#print()
count += 1
print(count)