We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 1e1cdbc commit ac251b2Copy full SHA for ac251b2
2020/day15/run.py
@@ -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