-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday20.py
34 lines (29 loc) · 959 Bytes
/
day20.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
from utils import get_input
from collections import deque
def mix(d, original_d):
for i, el in original_d:
d.rotate(-d.index((i,el)))
d.rotate(-d.popleft()[1])
d.appendleft((i,el))
return d
def get_sum(d, idx0):
d.rotate(-idx0)
s = 0
for _ in range(3):
d.rotate(-1000)
s += d[0][1]
return s
def part1(data):
d = mix(deque(enumerate(data)), deque(enumerate(data))) # save original indices, as values not unique in input
return get_sum(d, d.index((data.index(0), 0))) # assume 0 is unique tho...
def part2(data, key):
d2 = deque([(i,el*key) for i, el in enumerate(data)])
for _ in range(10):
d2 = mix(d2, deque([(i,el*key) for i, el in enumerate(data)]))
return get_sum(d2, d2.index((data.index(0), 0)))
if __name__ == "__main__":
day = 20
data = get_input(day)
data = list(map(int, data))
print(part1(data))
print(part2(data, key=811589153))