|
@@ -0,0 +1,16 @@
|
|
1
|
+with open('data/17.txt', 'r') as file:
|
|
2
|
+ steps = int(file.readline().strip())
|
|
3
|
+ buffer = []
|
|
4
|
+ position = 0
|
|
5
|
+ for i in range(2018):
|
|
6
|
+ buffer.insert(position, i)
|
|
7
|
+ position = (position + steps + 1) % (i + 1)
|
|
8
|
+ print(f'Part one: {buffer[(buffer.index(2017) + 1) % len(buffer)]}')
|
|
9
|
+
|
|
10
|
+ # The entry for zero is always at the end of our buffer, as we never call insert beyond the length of the list,
|
|
11
|
+ # so the entry after zero is always the one at position 0.
|
|
12
|
+ for i in range(2018, 50000001):
|
|
13
|
+ if position == 0:
|
|
14
|
+ after_zero = i
|
|
15
|
+ position = (position + steps + 1) % (i + 1)
|
|
16
|
+ print(f'Part two: {after_zero}')
|