summaryrefslogtreecommitdiffstats
path: root/3/1.py
diff options
context:
space:
mode:
Diffstat (limited to '3/1.py')
-rw-r--r--3/1.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/3/1.py b/3/1.py
new file mode 100644
index 0000000..0df8d8e
--- /dev/null
+++ b/3/1.py
@@ -0,0 +1,10 @@
+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))
+print(len(reduce(reducer, ({'^': (0, 1), 'v': (0, -1), '>': (1, 0), '<': (-1, 0)}[c] for c in open('input').read().rstrip('\n')), (d, (0, 0)))[0]))