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/13

+82
+36
2017/day13.py
··· 1 + import fileinput 2 + from itertools import count 3 + 4 + 5 + def scanner(height, time): 6 + """Return the position of a given scanner height at a given time.""" 7 + offset = time % ((height - 1) * 2) 8 + 9 + if offset > height - 1: 10 + return 2 * (height - 1) 11 + else: 12 + return offset 13 + 14 + 15 + HEIGHTS = {} 16 + 17 + for line in fileinput.input(): 18 + depth, rnge = [int(x) for x in line.strip().split(': ')] 19 + HEIGHTS[depth] = rnge 20 + 21 + # Part 1 22 + severity = 0 23 + for pos in HEIGHTS: 24 + if scanner(HEIGHTS[pos], pos) == 0: 25 + severity += pos * HEIGHTS[pos] 26 + 27 + print "Severity of whole trip:", severity 28 + 29 + # Part 2 30 + for delay in count(): 31 + for pos in HEIGHTS: 32 + if scanner(HEIGHTS[pos], delay + pos) == 0: 33 + break 34 + else: 35 + print "Minimal delay to not get caught:", delay 36 + break
+44
2017/inputs/13.txt
··· 1 + 0: 3 2 + 1: 2 3 + 2: 4 4 + 4: 6 5 + 6: 5 6 + 8: 6 7 + 10: 6 8 + 12: 4 9 + 14: 8 10 + 16: 8 11 + 18: 9 12 + 20: 8 13 + 22: 6 14 + 24: 14 15 + 26: 12 16 + 28: 10 17 + 30: 12 18 + 32: 8 19 + 34: 10 20 + 36: 8 21 + 38: 8 22 + 40: 12 23 + 42: 12 24 + 44: 12 25 + 46: 12 26 + 48: 14 27 + 52: 14 28 + 54: 12 29 + 56: 12 30 + 58: 12 31 + 60: 12 32 + 62: 14 33 + 64: 14 34 + 66: 14 35 + 68: 14 36 + 70: 14 37 + 72: 14 38 + 80: 18 39 + 82: 14 40 + 84: 20 41 + 86: 14 42 + 90: 17 43 + 96: 20 44 + 98: 24
+2
2017/outputs/13.txt
··· 1 + 1476 2 + 3937334