More golfing
authorNeil Smith <neil.git@njae.me.uk>
Tue, 18 Jul 2017 23:58:01 +0000 (00:58 +0100)
committerNeil Smith <neil.git@njae.me.uk>
Tue, 18 Jul 2017 23:58:01 +0000 (00:58 +0100)
02-lifts/lifts-solution.ipynb

index 723d33e92a3e4f5c93f9e9aab040b99003928093..dc7724f964ee36d13ca7945c622a46fee7167aea 100644 (file)
     "max(exits(instructions[:20]))"
    ]
   },
+  {
+   "cell_type": "code",
+   "execution_count": 12,
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "(209, 215)"
+      ]
+     },
+     "execution_count": 12,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "import functools\n",
+    "ds = {'^': +1, 'v': -1, '=': 0}\n",
+    "def s(p, c): return p[0] + ds[c], p[0] if c == '=' and p[0] > p[1] else p[1]\n",
+    "functools.reduce(s, open('02-lifts.txt').read().strip(), (0, float('-inf')))"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 13,
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "(209, 215)"
+      ]
+     },
+     "execution_count": 13,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "import functools\n",
+    "ds = {'^': +1, 'v': -1, '=': 0}\n",
+    "functools.reduce(lambda p, c: (p[0] + ds[c], p[0] if c == '=' and p[0] > p[1] else p[1]), open('02-lifts.txt').read().strip(), (0, 0))"
+   ]
+  },
   {
    "cell_type": "code",
    "execution_count": null,