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 solution for 2016/15

+31
+25
2016/day15.py
··· 1 + import re 2 + import fileinput 3 + import itertools 4 + from utils import parse_line 5 + 6 + 7 + def button_timing(discs): 8 + """Returns the first time at which the button should be pressed.""" 9 + for i in itertools.count(): 10 + for time, (positions, initial) in enumerate(discs, start=i+1): 11 + if (initial + time) % positions != 0: 12 + break 13 + else: 14 + return i 15 + 16 + 17 + DISCS = [] 18 + DISC_RE = re.compile(r'Disc #\d+ has (\d+) positions; at time=0, it is at position (\d+).') 19 + 20 + for line in fileinput.input(): 21 + disc = parse_line(DISC_RE, line.strip()) 22 + DISCS.append(disc) 23 + 24 + print "Timing to press button:", button_timing(DISCS) 25 + print "Timing with added disc:", button_timing(DISCS + [(11, 0)])
+6
2016/input15.txt
··· 1 + Disc #1 has 13 positions; at time=0, it is at position 10. 2 + Disc #2 has 17 positions; at time=0, it is at position 15. 3 + Disc #3 has 19 positions; at time=0, it is at position 17. 4 + Disc #4 has 7 positions; at time=0, it is at position 1. 5 + Disc #5 has 5 positions; at time=0, it is at position 0. 6 + Disc #6 has 3 positions; at time=0, it is at position 1.