Day 3 - Advent of Code 2015
Working solutions for the day 3 puzzles.
Part One
""" day_03_01.py """
# usage: python3 day_03_01.py < input
import sys
deltas = {'^': (0, 1), '>': (1, 0), 'v': (0, -1), '<': (-1, 0)}
x, y = 0, 0
log = {(x, y)}
for order in sys.stdin.read():
dx, dy = deltas[order]
x, y = x + dx, y + dy
log = log | {(x, y)}
print(len(log))
Part Two
""" day_03_02.py """
# usage: python3 day_03_02.py < input
import sys
deltas = {'^': (0, 1), '>': (1, 0), 'v': (0, -1), '<': (-1, 0)}
santa = 0, 0
robot = 0, 0
log = {santa, robot}
robot_turn = False
for order in sys.stdin.read():
dx, dy = deltas[order]
if not robot_turn:
santa = santa[0] + dx, santa[1] + dy
log = log | {santa}
else:
robot = robot[0] + dx, robot[1] + dy
log = log | {robot}
robot_turn = not robot_turn
print(len(log))