blob: 521d522a6373c686ac39defbee0628f7c4899310 (
plain)
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
|
"""Day 15.
The 30000000 takes a while to complete
"""
with open("input") as f:
memory = list(map(int, f.read().rstrip().split(",")))
data = {val: {"position": pos + 1, "count": 1} for pos, val in enumerate(memory)}
pos = len(memory) + 1
last = memory[-1]
# for x in range(2020 - pos + 1):
for x in range(30000000 - pos + 1):
if data[last]["count"] == 1:
val = 0
else:
x = pos - 1
y = data[last]["position"]
val = x - y
data[last]["position"] = x
if val not in data:
data[val] = {"position": pos, "count": 1}
last = val
data[val]["count"] += 1
pos += 1
print(val)
|