-
Notifications
You must be signed in to change notification settings - Fork 0
/
day_14_part_2.py
62 lines (56 loc) · 1.42 KB
/
day_14_part_2.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
60
61
62
from icecream import ic
import itertools
def move_left(m):
new_m = []
for i in range(len(m)):
row = m[i]
parts = []
o = []
d = []
for c in row:
if c == 'O':
o.append('O')
continue
if c == '.':
d.append('.')
continue
if c == '#':
parts.append(o + d + ['#'])
o = []
d = []
continue
parts.append(o + d)
new_m.append(list(itertools.chain(*parts)))
return new_m
def rotate_matrix(m):
return [list(x) for x in list(zip(*m[::-1]))]
def main():
m = []
with open('data/day14.data') as f:
for row in f:
m.append([c for c in row.strip()])
move_left(m)
# ic(m)
cycle_count = 1_000_000
for i in range(cycle_count):
if i % 1_000_000 == 0:
ic(i)
m = rotate_matrix(m)
m = move_left(m) # upwards
m = rotate_matrix(m)
m = move_left(m) # leftwards
m = rotate_matrix(m)
m = move_left(m) # downwards
m = rotate_matrix(m)
m = move_left(m) # rightwards
# ic(m)
res = 0
multiplier = len(m)
for y in range(len(m)):
for x in range(len(m[0])):
if m[y][x] == 'O':
res += multiplier
multiplier -= 1
ic(res)
if __name__ == '__main__':
main()