Last active
December 3, 2015 20:05
-
-
Save Ape/c19d1aa55ceddbc2932b to your computer and use it in GitHub Desktop.
advent3.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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