mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-25 21:00:31 +01:00
Move 2015 out of the way.
This commit is contained in:
1
2015/day-03/input.txt
Normal file
1
2015/day-03/input.txt
Normal file
File diff suppressed because one or more lines are too long
29
2015/day-03/solution.py
Normal file
29
2015/day-03/solution.py
Normal file
@@ -0,0 +1,29 @@
|
||||
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))
|
||||
Reference in New Issue
Block a user