X-Git-Url: https://git.njae.me.uk/?p=advent-of-code-15.git;a=blobdiff_plain;f=advent17.ipynb;fp=advent17.ipynb;h=180961dd21fb67750e9f9accbb238d0b838cb742;hp=9e175afce84c6c0a918adde1a4eadfafd0f7299f;hb=3ef5b5940e320b9792f02f99a7ca67fe668f0a7c;hpb=39525ef9a82b9e7e738e6c13fcc2067e7a0818a4 diff --git a/advent17.ipynb b/advent17.ipynb index 9e175af..180961d 100644 --- a/advent17.ipynb +++ b/advent17.ipynb @@ -25,7 +25,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 2, "metadata": { "collapsed": true }, @@ -36,33 +36,59 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [ { - "data": { - "text/plain": [ - "654" - ] - }, - "execution_count": 26, - "metadata": {}, - "output_type": "execute_result" + "name": "stdout", + "output_type": "stream", + "text": [ + "100 loops, best of 3: 14.2 ms per loop\n" + ] } ], "source": [ + "%%timeit\n", "partials = []\n", "for c in containers:\n", " new_partials = []\n", " for p in partials:\n", " if sum(p) + c <= target:\n", " new_partials += [[c] + p]\n", - " new_partials += [p]\n", " if c <= target:\n", " new_partials += [[c]]\n", - " partials = new_partials\n", + " partials += new_partials\n", + "solutions = list(filter(lambda p: sum(p) == target, partials))\n", + "len(solutions)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1 loops, best of 3: 753 ms per loop\n" + ] + } + ], + "source": [ + "%%timeit\n", + "partials = []\n", + "for c in containers:\n", + " new_partials = []\n", + " for p in partials:\n", + " if sum(p) + c <= target:\n", + " partials = [[c] + p] + partials\n", + " if c <= target:\n", + " partials = [[c]] + partials\n", "solutions = list(filter(lambda p: sum(p) == target, partials))\n", "len(solutions)" ] @@ -193,7 +219,7 @@ }, { "cell_type": "code", - "execution_count": 66, + "execution_count": 9, "metadata": { "collapsed": true }, @@ -204,7 +230,7 @@ }, { "cell_type": "code", - "execution_count": 63, + "execution_count": 10, "metadata": { "collapsed": false }, @@ -223,7 +249,7 @@ }, { "cell_type": "code", - "execution_count": 64, + "execution_count": 11, "metadata": { "collapsed": false }, @@ -234,7 +260,7 @@ "[True, False, False, False, True, True, False, False]" ] }, - "execution_count": 64, + "execution_count": 11, "metadata": {}, "output_type": "execute_result" } @@ -245,7 +271,7 @@ }, { "cell_type": "code", - "execution_count": 59, + "execution_count": 12, "metadata": { "collapsed": false }, @@ -256,13 +282,12 @@ "[]" ] }, - "execution_count": 59, + "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "import itertools\n", "valids = []\n", "c_small = containers[:5]\n", "for i in range(2**len(c_small)):\n", @@ -275,24 +300,21 @@ }, { "cell_type": "code", - "execution_count": 65, + "execution_count": 13, "metadata": { "collapsed": false }, "outputs": [ { - "data": { - "text/plain": [ - "654" - ] - }, - "execution_count": 65, - "metadata": {}, - "output_type": "execute_result" + "name": "stdout", + "output_type": "stream", + "text": [ + "1 loops, best of 3: 4.41 s per loop\n" + ] } ], "source": [ - "import itertools\n", + "%%timeit\n", "valids = []\n", "for i in range(2**len(containers)):\n", " mask = int_to_bitstring(i, len(containers))\n",