My Advent of Code solutions in Python. kevinyap.ca/2019/12/going-fast-in-advent-of-code/
advent-of-code python
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add 2017/17

+34
+31
2017/day17.py
··· 1 + import fileinput 2 + 3 + INC = int(fileinput.input()[0]) 4 + 5 + # Part 1 6 + spinlock = [0] 7 + pos = 0 8 + 9 + for i in range(1, 2017 + 1): 10 + pos = (pos + INC) % len(spinlock) 11 + spinlock.insert((pos + 1), i) 12 + pos += 1 13 + 14 + val = spinlock[spinlock.index(2017) + 1] 15 + print "Value after 2017 in small buffer:", val 16 + 17 + # Part 2 18 + snd_elem = None 19 + lock_len = 1 20 + pos = 0 21 + 22 + for i in range(1, 50000000 + 1): 23 + pos = (pos + INC) % lock_len 24 + 25 + if pos == 0: 26 + snd_elem = i 27 + 28 + lock_len += 1 29 + pos += 1 30 + 31 + print "Value after 0 in large buffer:", snd_elem
+1
2017/inputs/17.txt
··· 1 + 324
+2
2017/outputs/17.txt
··· 1 + 1306 2 + 20430489