diff options
Diffstat (limited to '3/2.py')
-rw-r--r-- | 3/2.py | 13 |
1 files changed, 13 insertions, 0 deletions
@@ -0,0 +1,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)) |