Browse Source

Day 17.

master
Chris Smith 6 years ago
parent
commit
ed28564c71
2 changed files with 17 additions and 0 deletions
  1. 16
    0
      17.py
  2. 1
    0
      data/17.txt

+ 16
- 0
17.py View File

@@ -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}')

+ 1
- 0
data/17.txt View File

@@ -0,0 +1 @@
1
+355

Loading…
Cancel
Save