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

+37
+34
2017/day03.py
··· 1 + import fileinput 2 + from itertools import count 3 + 4 + from utils import Point, DIRS 5 + 6 + target = int(fileinput.input()[0]) 7 + pos = Point(0, 0) 8 + seen = {pos: 1} 9 + facing = 1 10 + 11 + answer_1 = None 12 + answer_2 = None 13 + 14 + for i in count(start=2): 15 + pos = pos + DIRS[facing] 16 + 17 + value = sum(seen.get(p, 0) for p in pos.neighbours_8()) 18 + seen[pos] = value 19 + 20 + if i == target and not answer_1: 21 + answer_1 = pos.manhattan 22 + 23 + if value > target and not answer_2: 24 + answer_2 = value 25 + 26 + # Check if we should move straight or turn left next 27 + if (pos + DIRS[(facing - 1) % 4] not in seen): 28 + facing = (facing - 1) % 4 29 + 30 + if (answer_1 is not None) and (answer_2 is not None): 31 + break 32 + 33 + print "Step to access port:", answer_1 34 + print "First value larger than puzzle input:", answer_2
+1
2017/inputs/03.txt
··· 1 + 277678
+2
2017/outputs/03.txt
··· 1 + 475 2 + 279138