Skip to content

Instantly share code, notes, and snippets.

@Ape
Last active December 3, 2015 20:05
Show Gist options
  • Save Ape/c19d1aa55ceddbc2932b to your computer and use it in GitHub Desktop.
Save Ape/c19d1aa55ceddbc2932b to your computer and use it in GitHub Desktop.
advent3.py
#!/usr/bin/env python3
import sys
MOVES = {
">": ( 1, 0),
"<": (-1, 0),
"^": ( 0, 1),
"v": ( 0, -1),
}
def houses(steps):
x = 0
y = 0
for step in steps:
dx, dy = MOVES[step]
x += dx
y += dy
yield (x, y)
data = sys.stdin.readlines()[0].strip()
santa = set(houses(data[0::2]))
robo = set(houses(data[1::2]))
unique = len(santa | robo)
print(unique)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment