From: Neil Smith Date: Tue, 18 Jul 2017 23:58:01 +0000 (+0100) Subject: More golfing X-Git-Url: https://git.njae.me.uk/?a=commitdiff_plain;h=79edb0475322c1090597983d34e53a11056af0b8;hp=d7db6acc4c4d5f065da2e95a313e376310a990e0;p=ou-summer-of-code-2017.git More golfing --- diff --git a/02-lifts/lifts-solution.ipynb b/02-lifts/lifts-solution.ipynb index 723d33e..dc7724f 100644 --- a/02-lifts/lifts-solution.ipynb +++ b/02-lifts/lifts-solution.ipynb @@ -509,6 +509,51 @@ "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,