From: Neil Smith Date: Tue, 15 Dec 2015 15:24:26 +0000 (+0000) Subject: Tweaked day 15 X-Git-Url: https://git.njae.me.uk/?a=commitdiff_plain;h=56e1be9ad16bcdf72f063083e7955f0145df4c2e;p=advent-of-code-15.git Tweaked day 15 --- diff --git a/SIGNED.md b/SIGNED.md index d5e829e..a8fa3c0 100644 --- a/SIGNED.md +++ b/SIGNED.md @@ -3,19 +3,19 @@ -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 -iQIcBAABCAAGBQJWb91xAAoJEJPB2e07Pgbq3uIP/2Ghn6t3ti/2lh0CEJTN4zZn -gkptVP1RUHSV9OfSg9SX07bY77qgWlFq0Go6G1bY4e9RtVMeR+U9AsPOcZOKBw7Z -HK3cACdOFZKCbUiI1+XeJJZE1/U+agz0jbtVeXQX5zwlUZTzMCBfr/E96wnEAFRE -Lyr/UN7c+7apzklfsXimR0qhR7lt9hGBRdqbASt3vrclWFkxh62uFlHbXNToYw80 -qJrtMem6wlYqCin+lrd8pj5hNsPvhG5r9yfrbcT3FH9zOc6AwDui9gTtzdm5b9R/ -Ru8/pRZxYIart88jpOn0XkJwbN3o4dnmvTiAMViDZhxIxkqDgiXe1eZ5bnSdc2Hw -C9+hAKaeP2F+f1dYeZYpkGZF6r/6NGNI7xrq/kwPbzYLV9/aCuVPfx2YVOzeNBYn -wW79gxuIo1LJgyDb2vma8QETwIPIz1P8I3iD7fUlMCo/V8Qg/HsOrJ0Py8RZUhbF -NY1tR+LzlWt1w25GPtAT5Ij+X++KbKsIRS3Vy3wN8VSYvkxiuSW1nWTIUUJZG5Lc -3hh5Vknmdh51XYakFgx9On0E8zwTUcoSpwD6OtoVKOf0VyaBiBpzWG+sdk7JqLeU -fIHaIK9VqzU/9/esaawe/a4gQEeel6zrhmSRES47zJiYek1S4+XHy32v+/PbLrWO -+5b6VO54SIdG6S5TMVxa -=6JYR +iQIcBAABCAAGBQJWcDCwAAoJEJPB2e07PgbqBMgP/24slgalE6HIj/JZBLJRZQPB +KRiTSui18MQyEHJ3ROPHUtt3dnJ8DBSCRh+o20ln2jtq7IkipheVap4WITJeGi6O +m4PqxfdDDWAlfa33tFDOllnfwP4x5+Ql9GIMGL5mB6JKr3Y+6q0JFr1K3jl7/GcT +yWSQ2H1C012lxhINgz9dIhHg6vCAzVy4DoXXeB0pW27nVEm9hw/jRzPP2a4/4YSC +11BoU0lu6TWNWYUP57GnG6td/OQ6RjC6FSJpEokRa0+Or1gvV1eWR7UfaJazk1MF +TI/TnN6Ob0Wiy0eGB5KCcDztK9M21EjuTpRfx9GhpD8y5eTl2ZkQ8OTkuvEal/Bv +nboV75P2vJOiaOs6wfGkCHRNV6f0km+VP5SHedcQ/OhC++MutoDaU2VXine1hF6B +le3/NA5Gch6uLqzJ+wVe+Z0X3Jh1M7VXo9NCK+o4LhPhE0l4rmhW0MBkS6R/CrSL +RFs5zlbzm6mtZKEjJg6xji/WVqrtg+B+kxiHnqawaq18rveQy/KqfWI3oG37mtW+ +sCVuagRVr4RcUpYgEmPmyJm94jQfaXvj4Y7RjpXqEhq61hpY21VfDEsE8CSo4TN6 +xF/zE0kzMz1uObfveJSt6KRNce4P441X9RBfdc4U6e5aZG5SeHmGEEqA2t2px1NY +83Z/rtENfdqQQkszdFwD +=ls8s -----END PGP SIGNATURE----- ``` @@ -27,52 +27,56 @@ fIHaIK9VqzU/9/esaawe/a4gQEeel6zrhmSRES47zJiYek1S4+XHy32v+/PbLrWO #### Expect ``` -size exec file contents - ./ -61 .directory 98a10e4b61e7a0e5156f6e0d5d3227255fd60f57ea34ae1b81bdd87c16bababb -384 .gitignore a93de2ae5c2a47a38599751d1f914566569dfa09dd1778e207117db6c71421dd -6394 advent-of-code-01.html 6155b76a1468f83176616650ca67af4a63c223442b7250571415225740627d17 -6521 advent-of-code-02.html dece9d48e80b27f854be07606fb0f3b1da6599d69cba1594fcda631010e57c07 -6253 advent-of-code-03.html 7dd8766e6ec8b92438657ad36326ce302432d526793a804ea7f6e62e6fdcec04 -5435 advent-of-code-04.html c550f004a8b0f5af1faf870ef0789008c3c5a9122a81ea3617cbb45cd93940e0 -7035 advent-of-code-05.html b538cae1feb365958c65882a323d2eccec214c1bebfccc2f2f3348d817ebd054 -6705 advent-of-code-06.html 76a0a89f9751e5a8b584b3c9bc0f33ab7ddee481d16f98ad71e61c0c6f3d6d08 -7190 advent-of-code-07.html 8555bc50c00f5b3d3e83b29e37169c553d4917c4cff517afbf73efb5ccd8ea23 -7936 advent-of-code-08.html 5d25c8ef68a3a34233d31e37bdef96381c7a777ef0bdf71209c1d9e163749b7a -5586 advent-of-code-09.html d26140599aa30b87beb1126eebbe78476cff57d5f950fbe729a449f4d7aa0fb6 -5929 advent-of-code-10.html a4936eee59d96d9eedbe177299ac8c5fc94595db7f2959b6d54070ba79599b6f -6562 advent-of-code-11.html f6ef213572c945e0f55ea5cef3dbeffa7a6c22e5fda2c2d56365117886d88863 -5919 advent-of-code-12.html cc84ec3c04da02c7d566f7c0f3ea08a4abf57f2931d7dc87915b2a88d1944e8c -7192 advent-of-code-13.html 9b84752c8f387cd03f85299c78837cea35c64a0276db7dbef9e33f82971b47e2 -6940 advent-of-code-14.html 434d5f7542d85beb72a03306cfa7d43e18a7857d4e031018747249e2edc00355 -109395 advent-of-code.ipynb 7292eeb9a8019f6931037c70105ab96bf691074dbe963736b6429cb4d4373f51 -25607 advent01.ipynb c33ad39a77803a6870dd74998da98e3bb9c2c2db37c34167b330a01d663717e7 -7001 advent01.txt 79312922877bdedd09ce0886a42b3d7f7ed092e2218579fb7d6ac1cb38cedebe -2422 advent02.ipynb 7576c0aa7bdb2eff73fddf62007271be781c19fd7ad91fd0dd75053a8c391884 -8112 advent02.txt b292113c3aa7b376a88a6ea57a5f30edef6c50e6aba7e947fad6f7a6a11e5156 -2676 advent03.ipynb 3078936407038050d75235c1367b83d30a8d6cce8d8fde8063e3c0928cc9277d -8193 advent03.txt a76a8c8606405157a5a28d79960a5125212c6d5b1db57f222fc52272bf4f95b4 -2611 advent04.ipynb 7698d77125561b78e8965c6b26150f7d2e6ca23e918ed4c7a95fa36c534ffd5d -3514 advent05.ipynb b726978b2fc36660e7afa2433db3cc94c962cf46b30e05b5c1f73825a4186093 -17000 advent05.txt 101c771d218044ec73cd83ff97d73b004df99475447f9fe66b8e9b58d01b0f8c -11641 advent06.ipynb 9ff7b2a9760e5551a3c51e978f4696c9872c7467bdaa93a1675c5d86aa41a719 -9525 advent06.txt 0e9c027e1983a02fec4d3d856630b1fad112879cfc1dfb630ffa8a98f2953a67 -24067 advent07.ipynb b9a2fb8436ee35b0e4e743d5927d38802edede5d27ae02d09671da7c5bd2f56b -5303 advent07.txt 808248ff71a40272677ae61d4270cfbbe911c1cca7023f19a30ec70ad777ae2d -5012 advent08.ipynb d4508791aa6ce8f0618da68e58c30089e0e8a9954a617ba8530e9c32519eeb44 -6495 advent08.txt fed7e63100a843e538fe07f1fab2ea2236a9f4fc1b10ec309c5e30812647bb19 -13073 advent09.ipynb 8f69c9554c3bf05750460f2f98bc96799ae1a9e079e02696d6429f9591f6dc90 -715 advent09.txt b7fe7bf169dbd6e35de3cf1aff257046edf9919986ce92175d62c7abf28da736 -3696 advent10.ipynb 814d99c479c133f06c1176617807db41df95727445c2130654a8cf0f2891048c -5892 advent11.ipynb f2321f15d9ebe936f0e3305672a789f48919f605a9ac341d3704f398ba7233b4 -3217 advent12.ipynb b794e2f0b624e9b1b9ed11065a5298b09daa9116c38ae07ab2731c7fce797289 -42142 advent12.json f7b94a7f5aa11f94edea6a1727fcf81613306c53a9a84078ff557d216cfbb6c9 -10185 advent13.ipynb 30e1bfd714003c6ee5a4e23f8e1d5874658be3fae51b1e709451d1d55086469e -3465 advent13.txt a8610959b8c1388f53a7720828c8a1cad08b1c95661d198e01157fc83ef08605 -14202 advent14.ipynb faf4ce12b0317e0c9218869f980861d4fd902c5bdb2072a0a2d28aadb9506919 -656 advent14.txt 686da937ed08c3039b8782c7fd3e4b2cf45fcf1cfeada8bca4007e5020d3bd55 -6438 advent15.ipynb e07b8e19c36c5e5f7e5670938a3a83ec28f5224eddc42d6164fac23f02315101 -274 advent15.txt 7a8a96fd6321651f56df6018bf9c9ba3670af027504e294906d68b34ccff3910 +size exec file contents + ./ +61 .directory 98a10e4b61e7a0e5156f6e0d5d3227255fd60f57ea34ae1b81bdd87c16bababb +384 .gitignore a93de2ae5c2a47a38599751d1f914566569dfa09dd1778e207117db6c71421dd +6394 advent-of-code-01.html 6155b76a1468f83176616650ca67af4a63c223442b7250571415225740627d17 +6521 advent-of-code-02.html dece9d48e80b27f854be07606fb0f3b1da6599d69cba1594fcda631010e57c07 +6253 advent-of-code-03.html 7dd8766e6ec8b92438657ad36326ce302432d526793a804ea7f6e62e6fdcec04 +5435 advent-of-code-04.html c550f004a8b0f5af1faf870ef0789008c3c5a9122a81ea3617cbb45cd93940e0 +7035 advent-of-code-05.html b538cae1feb365958c65882a323d2eccec214c1bebfccc2f2f3348d817ebd054 +6705 advent-of-code-06.html 76a0a89f9751e5a8b584b3c9bc0f33ab7ddee481d16f98ad71e61c0c6f3d6d08 +7190 advent-of-code-07.html 8555bc50c00f5b3d3e83b29e37169c553d4917c4cff517afbf73efb5ccd8ea23 +7936 advent-of-code-08.html 5d25c8ef68a3a34233d31e37bdef96381c7a777ef0bdf71209c1d9e163749b7a +5586 advent-of-code-09.html d26140599aa30b87beb1126eebbe78476cff57d5f950fbe729a449f4d7aa0fb6 +5929 advent-of-code-10.html a4936eee59d96d9eedbe177299ac8c5fc94595db7f2959b6d54070ba79599b6f +6562 advent-of-code-11.html f6ef213572c945e0f55ea5cef3dbeffa7a6c22e5fda2c2d56365117886d88863 +5919 advent-of-code-12.html cc84ec3c04da02c7d566f7c0f3ea08a4abf57f2931d7dc87915b2a88d1944e8c +7192 advent-of-code-13.html 9b84752c8f387cd03f85299c78837cea35c64a0276db7dbef9e33f82971b47e2 +6940 advent-of-code-14.html 434d5f7542d85beb72a03306cfa7d43e18a7857d4e031018747249e2edc00355 +8545 advent-of-code-15.html ce34ca2c904d7a1d99fe3bc15dffa1a084e7e07248a46e6b50aacb623e4a6c9d + advent-of-code-15_files/ +821 css 2b2caac1348f4fe3e6c58c5fcbeaf56f12a704c07efacb39ae81980f69f285a0 +11201 style.css 6a0bf14bde57190ab82dc93d43e04753da916ca3cdd4b8cb9c063616c789df94 +109395 advent-of-code.ipynb 7292eeb9a8019f6931037c70105ab96bf691074dbe963736b6429cb4d4373f51 +25607 advent01.ipynb c33ad39a77803a6870dd74998da98e3bb9c2c2db37c34167b330a01d663717e7 +7001 advent01.txt 79312922877bdedd09ce0886a42b3d7f7ed092e2218579fb7d6ac1cb38cedebe +2422 advent02.ipynb 7576c0aa7bdb2eff73fddf62007271be781c19fd7ad91fd0dd75053a8c391884 +8112 advent02.txt b292113c3aa7b376a88a6ea57a5f30edef6c50e6aba7e947fad6f7a6a11e5156 +2676 advent03.ipynb 3078936407038050d75235c1367b83d30a8d6cce8d8fde8063e3c0928cc9277d +8193 advent03.txt a76a8c8606405157a5a28d79960a5125212c6d5b1db57f222fc52272bf4f95b4 +2611 advent04.ipynb 7698d77125561b78e8965c6b26150f7d2e6ca23e918ed4c7a95fa36c534ffd5d +3514 advent05.ipynb b726978b2fc36660e7afa2433db3cc94c962cf46b30e05b5c1f73825a4186093 +17000 advent05.txt 101c771d218044ec73cd83ff97d73b004df99475447f9fe66b8e9b58d01b0f8c +11641 advent06.ipynb 9ff7b2a9760e5551a3c51e978f4696c9872c7467bdaa93a1675c5d86aa41a719 +9525 advent06.txt 0e9c027e1983a02fec4d3d856630b1fad112879cfc1dfb630ffa8a98f2953a67 +24067 advent07.ipynb b9a2fb8436ee35b0e4e743d5927d38802edede5d27ae02d09671da7c5bd2f56b +5303 advent07.txt 808248ff71a40272677ae61d4270cfbbe911c1cca7023f19a30ec70ad777ae2d +5012 advent08.ipynb d4508791aa6ce8f0618da68e58c30089e0e8a9954a617ba8530e9c32519eeb44 +6495 advent08.txt fed7e63100a843e538fe07f1fab2ea2236a9f4fc1b10ec309c5e30812647bb19 +13073 advent09.ipynb 8f69c9554c3bf05750460f2f98bc96799ae1a9e079e02696d6429f9591f6dc90 +715 advent09.txt b7fe7bf169dbd6e35de3cf1aff257046edf9919986ce92175d62c7abf28da736 +3696 advent10.ipynb 814d99c479c133f06c1176617807db41df95727445c2130654a8cf0f2891048c +5892 advent11.ipynb f2321f15d9ebe936f0e3305672a789f48919f605a9ac341d3704f398ba7233b4 +3217 advent12.ipynb b794e2f0b624e9b1b9ed11065a5298b09daa9116c38ae07ab2731c7fce797289 +42142 advent12.json f7b94a7f5aa11f94edea6a1727fcf81613306c53a9a84078ff557d216cfbb6c9 +10185 advent13.ipynb 30e1bfd714003c6ee5a4e23f8e1d5874658be3fae51b1e709451d1d55086469e +3465 advent13.txt a8610959b8c1388f53a7720828c8a1cad08b1c95661d198e01157fc83ef08605 +14202 advent14.ipynb faf4ce12b0317e0c9218869f980861d4fd902c5bdb2072a0a2d28aadb9506919 +656 advent14.txt 686da937ed08c3039b8782c7fd3e4b2cf45fcf1cfeada8bca4007e5020d3bd55 +10488 advent15.ipynb a5f0886978fe096f62715ee54ebdcd20fa82b4a34afc4edacaac48a2006da765 +274 advent15.txt 7a8a96fd6321651f56df6018bf9c9ba3670af027504e294906d68b34ccff3910 ``` #### Ignore diff --git a/advent15.ipynb b/advent15.ipynb index 5152490..06fbcae 100644 --- a/advent15.ipynb +++ b/advent15.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 6, + "execution_count": 3, "metadata": { "collapsed": true }, @@ -14,7 +14,7 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 4, "metadata": { "collapsed": false }, @@ -28,7 +28,7 @@ " 'Sugar: capacity 0, durability 0, flavor -2, texture 2, calories 1']" ] }, - "execution_count": 39, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -52,7 +52,7 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 5, "metadata": { "collapsed": false }, @@ -82,7 +82,7 @@ " 'texture': 2}}" ] }, - "execution_count": 40, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } @@ -103,7 +103,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 6, "metadata": { "collapsed": false }, @@ -211,6 +211,18 @@ " range(capacity+1), range(capacity+1))))" ] }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "def recipe(t, capacity):\n", + " return [('Frosting', t[0]), ('Butterscotch', t[1]), ('Candy', t[2]), ('Sugar', capacity-sum(t))]" + ] + }, { "cell_type": "code", "execution_count": 32, @@ -238,6 +250,33 @@ " range(capacity+1))))" ] }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "collapsed": false, + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "18965440" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "capacity = 100\n", + "max(score(recipe(t, capacity), ingredients) \n", + " for t in filter(lambda t: sum(t) <= capacity,\n", + " itertools.product(range(capacity+1), range(capacity+1), \n", + " range(capacity+1))))" + ] + }, { "cell_type": "code", "execution_count": 38, @@ -290,7 +329,7 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 10, "metadata": { "collapsed": false }, @@ -346,7 +385,7 @@ }, { "cell_type": "code", - "execution_count": 42, + "execution_count": 11, "metadata": { "collapsed": false, "scrolled": true @@ -358,16 +397,15 @@ "15862900" ] }, - "execution_count": 42, + "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "capacity = 100\n", - "max(score([('Frosting', f), ('Butterscotch', b), ('Candy', c), ('Sugar', capacity-(f+b+c))], ingredients) \n", - " for f, b, c in filter(lambda t: calories([('Frosting', t[0]), ('Butterscotch', t[1]), \n", - " ('Candy', t[2]), ('Sugar', capacity-sum(t))], ingredients) == 500,\n", + "max(score(recipe(t, capacity), ingredients) \n", + " for t in filter(lambda t: calories(recipe(t, capacity), ingredients) == 500,\n", " filter(lambda t: sum(t) <= capacity,\n", " itertools.product(range(capacity+1), range(capacity+1), \n", " range(capacity+1)))))"