1
2
3
4
5
6
7
8
9
10
11
12
13
|
from functools import reduce
from collections import defaultdict
d = defaultdict(int)
d[(0, 0)] = 1
def reducer(state, move):
d, pos = state
npos = (pos[0] + move[0], pos[1] + move[1])
d[npos] += 1
return (d, (npos))
instrs = [{'^': (0, 1), 'v': (0, -1), '>': (1, 0), '<': (-1, 0)}[c] for c in open('input').read().rstrip('\n')]
d, _ = reduce(reducer, (instr for i, instr in enumerate(instrs) if i % 2 == 0), (d, (0, 0)))
d, _ = reduce(reducer, (instr for i, instr in enumerate(instrs) if i % 2 == 1), (d, (0, 0)))
print(len(d))
|