Something went wrong. Try again.
My Advent of Code solutions in Python. kevinyap.ca/2019/12/going-fast-in-advent-of-code
advent-of-code python
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738import fileinputfrom utils import Point
DIRS = [ Point(0, 1), # north Point(1, 0), # east Point(0, -1), # south Point(-1, 0) # west]
seen = set()double_visit = ''
pos = Point(0, 0)facing = 0
for line in fileinput.input(): directions = line.split(', ')
for d in directions: turn = d[0] steps = int(d[1:])
if turn == 'L': facing = (facing - 1) % 4 else: facing = (facing + 1) % 4
for _ in range(steps): pos += DIRS[facing] if not double_visit and pos in seen: double_visit = "First double-visit at ({}, {}) ({} blocks away)".format(pos.x, pos.y, pos.manhattan) else: seen.add(pos)
print "Easter Bunny HQ is at ({}, {}) ({} blocks away)".format(pos.x, pos.y, pos.manhattan)print double_visit