mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-25 21:00:31 +01:00
30 lines
606 B
Python
30 lines
606 B
Python
from __future__ import print_function
|
|
import fileinput
|
|
|
|
def move(pos, c):
|
|
if c == '<':
|
|
pos = (pos[0] + 1, pos[1])
|
|
elif c == '>':
|
|
pos = (pos[0] - 1, pos[1])
|
|
elif c == '^':
|
|
pos = (pos[0], pos[1] + 1)
|
|
elif c == 'v':
|
|
pos = (pos[0], pos[1] - 1)
|
|
|
|
return pos
|
|
|
|
pos = (0, 0)
|
|
pos2 = pos
|
|
places = set([pos])
|
|
|
|
for line in fileinput.input():
|
|
for idx,c in enumerate(line):
|
|
if idx % 2 == 0:
|
|
pos = move(pos, c)
|
|
places.add(pos)
|
|
else:
|
|
pos2 = move(pos2, c)
|
|
places.add(pos2)
|
|
|
|
print("Houses:", len(places))
|