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 35 lines 643 B view raw
1import fileinput 2from utils import Point, DIRS 3 4DIR_MAP = 'NESW' 5 6p1 = Point(0, 0) 7p2 = Point(0, 0) 8wp = Point(10, 1) 9 10facing = 1 # start at 1 to match DIRS 11 12for line in fileinput.input(): 13 d = line[0] 14 n = int(line[1:]) 15 16 if d in DIR_MAP: 17 delta = DIRS[DIR_MAP.index(d)] * n 18 p1 += delta 19 wp += delta 20 21 elif d == 'L' or d == 'R': 22 turns = n // 90 23 if d == 'L': 24 turns = 4 - turns 25 26 facing = (facing + turns) % 4 27 28 wp = wp.rotate(turns) 29 30 elif d == 'F': 31 p1 += DIRS[facing] * n 32 p2 += wp * n 33 34print "Part 1:", p1.manhattan 35print "Part 2:", p2.manhattan