mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-25 21:00:31 +01:00
Day 3 and 4 solutions.
This commit is contained in:
1
day3-input.txt
Normal file
1
day3-input.txt
Normal file
File diff suppressed because one or more lines are too long
28
day3.py
Normal file
28
day3.py
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
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