Skip to content

Commit ac251b2

Browse files
committed
added 2020/day15
1 parent 1e1cdbc commit ac251b2

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

2020/day15/run.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#! /usr/bin/env python3
2+
3+
input = "20,9,11,0,1,2"
4+
5+
spoken = list(map(int, input.split(',')))
6+
last = dict((n, i) for i, n in enumerate(spoken[:-1]))
7+
8+
def play(limit):
9+
while len(spoken) < limit:
10+
number = spoken[-1]
11+
if number in last:
12+
spoken.append(len(spoken) - 1 - last[number])
13+
else:
14+
spoken.append(0)
15+
last[number] = len(spoken) - 2
16+
17+
# Part One
18+
19+
play(2020)
20+
print(spoken[2020-1])
21+
22+
# Part Two
23+
24+
play(30_000_000)
25+
print(spoken[30_000_000-1])

0 commit comments

Comments
 (0)