summaryrefslogtreecommitdiffstats
path: root/3/2.py
diff options
context:
space:
mode:
Diffstat (limited to '3/2.py')
-rw-r--r--3/2.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/3/2.py b/3/2.py
new file mode 100644
index 0000000..daeaac6
--- /dev/null
+++ b/3/2.py
@@ -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))