"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,