Browse Source

Add day 15

master
mid-kid 4 years ago
parent
commit
5317bade8a
  1. 22
      d15.py
  2. 1
      d15_input.txt
  3. 2
      d15_output.txt

22
d15.py

@ -0,0 +1,22 @@
#!/usr/bin/env python3
from sys import argv
i = [int(x) for x in open(argv[1]).read().strip().split(",")]
a = {x:t+1 for t,x in enumerate(i[:-1])}
t = len(i)
l = i[-1]
def f(x):
global l,t
while t < x:
if l in a:
n = t - a[l]
else:
n = 0
a[l] = t
t += 1
l = n
return l
print(f(2020))
print(f(30000000))

1
d15_input.txt

@ -0,0 +1 @@
0,13,16,17,1,10,6

2
d15_output.txt

@ -0,0 +1,2 @@
276
31916
Loading…
Cancel
Save