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.

Update day15.py

+10 -3
+10 -3
2016/day15.py
··· 1 1 import re 2 2 import fileinput 3 - import itertools 4 3 from utils import parse_line 5 4 6 5 7 6 def button_timing(discs): 8 7 """Returns the first time at which the button should be pressed.""" 9 - for i in itertools.count(): 8 + largest_disc = max(discs) 9 + stride, initial_pos = largest_disc 10 + disc_num = discs.index(largest_disc) + 1 11 + 12 + i = (stride - initial_pos - disc_num) % stride 13 + 14 + while True: 10 15 for time, (positions, initial) in enumerate(discs, start=i+1): 11 16 if (initial + time) % positions != 0: 12 17 break 13 18 else: 14 19 return i 20 + 21 + i += stride 15 22 16 23 17 24 DISCS = [] ··· 22 29 DISCS.append(disc) 23 30 24 31 print "Timing to press button:", button_timing(DISCS) 25 - print "Timing with added disc:", button_timing(DISCS + [(11, 0)]) 32 + print "Timing with added disc:", button_timing(DISCS + [[11, 0]])