In [1]:
myinput = '/home/fmuinos/projects/adventofcode/2015/ferran/inputs/input3.txt'
In [15]:
from collections import defaultdict
def move(pos, char):
new0 = pos[0] - (char == '<') + (char == '>')
new1 = pos[1] - (char == 'v') + (char == '^')
return (new0, new1)
In [22]:
pos = (0,0)
visited = defaultdict(int)
visited[pos] += 1
with open(myinput, 'rt') as f:
line = next(f).rstrip()
for char in line:
pos = move(pos, char)
visited[pos] += 1
len(visited)
Out[22]:
In [24]:
santa = (0,0)
robosanta = (0,0)
visited = defaultdict(int)
visited[santa] += 2
counter = 0
with open(myinput, 'rt') as f:
line = next(f).rstrip()
for char in line:
if counter % 2 == 0:
santa = move(santa, char)
visited[santa] += 1
else:
robosanta = move(robosanta, char)
visited[robosanta] += 1
counter += 1
len(visited)
Out[24]: