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.

at main 34 lines 777 B view raw
1import fileinput 2from itertools import count 3 4from utils import Point, DIRS 5 6target = int(fileinput.input()[0]) 7pos = Point(0, 0) 8seen = {pos: 1} 9facing = 1 10 11answer_1 = None 12answer_2 = None 13 14for 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 33print "Step to access port:", answer_1 34print "First value larger than puzzle input:", answer_2