From: Neil Smith Date: Tue, 15 Dec 2015 09:29:14 +0000 (+0000) Subject: Started on day 15 X-Git-Url: https://git.njae.me.uk/?p=advent-of-code-15.git;a=commitdiff_plain;h=acab8ea30987c6ee2dcc88b43ca4f2a99af73b77 Started on day 15 --- diff --git a/SIGNED.md b/SIGNED.md index f17a89c..d5e829e 100644 --- a/SIGNED.md +++ b/SIGNED.md @@ -3,19 +3,19 @@ -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 -iQIcBAABCAAGBQJWbpWyAAoJEJPB2e07PgbqSqYP/2jlLEjZHz3y6q+inpV1kLHX -sM0B2SkvvV6KrQPL8s1jac0q0EQqgaQvy/M/dr8vPwfnw7ZCwEE3U4Jxpive7P8q -0QUL3Pg9fPqvwBBc81CT6xZIR+foKSEmZ4Di+w6//1gZvseb0X6PfGmwCB9lnLaW -AdGJEIa9pbTExiQzvuZamfnC4VFuYlCU82VsJIclG6UP3QdQ4sdh6JBC4jz+rHKx -CjmABv8N5G9Lib1kYSNvNYw+Ofbwv9CnA0YjlhTWz+ThXa6g9FA5LkF2Q9L96sA8 -YpA3AR9S7PQZutmpByB8nScRtdAr+r6G4aAML7a/VKT56PG+pEu8wOvVpfWEUtqG -TSb7IzLtd6TClT8HV2C+8x7ZDU0JbzzNVs+A8hepwGtP/xXuXjpuD25yzYHN5AGL -B25FxPKi1FD9CKOBnNb3NIoyD0QsLwn67ceXNRKJf6wt+cGLfSH0VZzU6hkvqihE -C+O9PeZzSEKZe7DYVqvZUHJQMHnlwhw36CCd3h6LzJALhtUmYqAe8TDcW1Dergl4 -Jg7oL7OEOpDZej+x5bqUm/n1EEDeO3UjUZenEohETLFTRp2c/KbrMsar3b/E2QU7 -dfOeMSx1ssINg2xDVX2J6fmSS5Z0UVXf+hQR/guvTnc3eTckS4oxcoIhO3h8exdV -HRxc6U+uv/9jnSRBOqJp -=KJpf +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 -----END PGP SIGNATURE----- ``` @@ -44,6 +44,7 @@ size exec file contents 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 @@ -70,6 +71,8 @@ size exec file contents 3465 advent13.txt a8610959b8c1388f53a7720828c8a1cad08b1c95661d198e01157fc83ef08605 14202 advent14.ipynb faf4ce12b0317e0c9218869f980861d4fd902c5bdb2072a0a2d28aadb9506919 656 advent14.txt 686da937ed08c3039b8782c7fd3e4b2cf45fcf1cfeada8bca4007e5020d3bd55 +6438 advent15.ipynb e07b8e19c36c5e5f7e5670938a3a83ec28f5224eddc42d6164fac23f02315101 +274 advent15.txt 7a8a96fd6321651f56df6018bf9c9ba3670af027504e294906d68b34ccff3910 ``` #### Ignore diff --git a/advent-of-code-14.html b/advent-of-code-14.html new file mode 100644 index 0000000..3486508 --- /dev/null +++ b/advent-of-code-14.html @@ -0,0 +1,145 @@ + + + + +Day 14 - Advent of Code + + + + + + +

Advent of Code

Neil Smith 28*
+ + + +
+

--- Day 14: Reindeer Olympics ---

This year is the Reindeer Olympics! Reindeer can fly at high speeds, but must rest occasionally to recover their energy. Santa would like to know which of his reindeer is fastest, and so he has them race.

+

Reindeer can only either be flying (always at their top speed) or resting (not moving at all), and always spend whole seconds in either state.

+

For example, suppose you have the following Reindeer:

+
    +
  • Comet can fly 14 km/s for 10 seconds, but then must rest for 127 seconds.
  • +
  • Dancer can fly 16 km/s for 11 seconds, but then must rest for 162 seconds.
  • +
+

After one second, Comet has gone 14 km, while Dancer has gone 16 km. After ten seconds, Comet has gone 140 km, while Dancer has gone 160 km. On the eleventh second, Comet begins resting (staying at 140 km), and Dancer continues on for a total distance of 176 km. On the 12th second, both reindeer are resting. They continue to rest until the 138th second, when Comet flies for another ten seconds. On the 174th second, Dancer flies for another 11 seconds.

+

In this example, after the 1000th second, both reindeer are resting, and Comet is in the lead at 1120 km (poor Dancer has only gotten 1056 km by that point). So, in this situation, Comet would win (if the race ended at 1000 seconds).

+

Given the descriptions of each reindeer (in your puzzle input), after exactly 2503 seconds, what distance has the winning reindeer traveled?

+
+

Your puzzle answer was 2655.

--- Part Two ---

Seeing how reindeer move in bursts, Santa decides he's not pleased with the old scoring system.

+

Instead, at the end of each second, he awards one point to the reindeer currently in the lead. (If there are multiple reindeer tied for the lead, they each get one point.) He keeps the traditional 2503 second time limit, of course, as doing otherwise would be entirely ridiculous.

+

Given the example reindeer from above, after the first second, Dancer is in the lead and gets one point. He stays in the lead until several seconds into Comet's second burst: after the 140th second, Comet pulls into the lead and gets his first point. Of course, since Dancer had been in the lead for the 139 seconds before that, he has accumulated 139 points by the 140th second.

+

After the 1000th second, Dancer has accumulated 689 points, while poor Comet, our old champion, only has 312. So, with the new scoring system, Dancer would win (if the race ended at 1000 seconds).

+

Again given the descriptions of each reindeer (in your puzzle input), after exactly 2503 seconds, how many points does the winning reindeer have?

+
+

Your puzzle answer was 1059.

Both parts of this puzzle are complete! They provide two gold stars: **

+

At this point, you should return to your advent calendar and try another puzzle.

+

If you still want to see it, you can get your puzzle input.

+

You can also + this puzzle.

+
+ + + + + + diff --git a/advent15.ipynb b/advent15.ipynb new file mode 100644 index 0000000..ebc895f --- /dev/null +++ b/advent15.ipynb @@ -0,0 +1,257 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 24, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "from collections import defaultdict\n", + "import itertools" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "['Frosting: capacity 4, durability -2, flavor 0, texture 0, calories 5',\n", + " 'Candy: capacity 0, durability 5, flavor -1, texture 0, calories 8',\n", + " 'Butterscotch: capacity -1, durability 0, flavor 5, texture 0, calories 6',\n", + " 'Sugar: capacity 0, durability 0, flavor -2, texture 2, calories 1']" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pi15 = [l.strip() for l in open('advent15.txt').readlines()]\n", + "pi15" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "{'Butterscotch': {'calories': 6,\n", + " 'capacity': -1,\n", + " 'durability': 0,\n", + " 'flavor': 5,\n", + " 'texture': 0},\n", + " 'Candy': {'calories': 8,\n", + " 'capacity': 0,\n", + " 'durability': 5,\n", + " 'flavor': -1,\n", + " 'texture': 0},\n", + " 'Frosting': {'calories': 5,\n", + " 'capacity': 4,\n", + " 'durability': -2,\n", + " 'flavor': 0,\n", + " 'texture': 0},\n", + " 'Sugar': {'calories': 1,\n", + " 'capacity': 0,\n", + " 'durability': 0,\n", + " 'flavor': -2,\n", + " 'texture': 2}}" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ingredients = {}\n", + "for l in pi15:\n", + " ls = l.split(': ')\n", + " name = ls[0]\n", + " props = ls[1].split(', ')\n", + " properties = {}\n", + " for p in props:\n", + " ps = p.split(' ')\n", + " properties[ps[0].strip()] = int(ps[1].strip())\n", + " ingredients[name] = properties\n", + "ingredients" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "def score(recipe, ingredients):\n", + " property_scores = defaultdict(int)\n", + " for ingredient, quantity in recipe:\n", + " for p in ingredients[ingredient]:\n", + " property_scores[p] += ingredients[ingredient][p] * quantity\n", + " total = 1\n", + " for p in property_scores:\n", + " total *= max(property_scores[p], 0)\n", + " return total" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "9396000000" + ] + }, + "execution_count": 34, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "score([('Frosting', 30), ('Butterscotch', 30), ('Candy', 30), ('Sugar', 10)], ingredients)" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": { + "collapsed": false, + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "[(0, 0, 0, 3),\n", + " (0, 0, 1, 2),\n", + " (0, 0, 2, 1),\n", + " (0, 0, 3, 0),\n", + " (0, 1, 0, 2),\n", + " (0, 1, 1, 1),\n", + " (0, 1, 2, 0),\n", + " (0, 2, 0, 1),\n", + " (0, 2, 1, 0),\n", + " (0, 3, 0, 0),\n", + " (1, 0, 0, 2),\n", + " (1, 0, 1, 1),\n", + " (1, 0, 2, 0),\n", + " (1, 1, 0, 1),\n", + " (1, 1, 1, 0),\n", + " (1, 2, 0, 0),\n", + " (2, 0, 0, 1),\n", + " (2, 0, 1, 0),\n", + " (2, 1, 0, 0),\n", + " (3, 0, 0, 0)]" + ] + }, + "execution_count": 31, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "capacity = 3\n", + "list(filter(lambda t: sum(t) == capacity,\n", + " itertools.product(range(capacity+1), range(capacity+1), \n", + " range(capacity+1), range(capacity+1))))" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": { + "collapsed": false, + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "10618782720" + ] + }, + "execution_count": 38, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "capacity = 100\n", + "max(score([('Frosting', f), ('Butterscotch', b), ('Candy', c), ('Sugar', s)], ingredients) \n", + " for b, c, f, s in filter(lambda t: sum(t) == capacity,\n", + " itertools.product(range(capacity+1), range(capacity+1), \n", + " range(capacity+1), range(capacity+1))))" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "ename": "TypeError", + "evalue": "unhashable type: 'slice'", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mingredients\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[1;31mTypeError\u001b[0m: unhashable type: 'slice'" + ] + } + ], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.4.3" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/advent15.txt b/advent15.txt new file mode 100644 index 0000000..634c6a5 --- /dev/null +++ b/advent15.txt @@ -0,0 +1,4 @@ +Frosting: capacity 4, durability -2, flavor 0, texture 0, calories 5 +Candy: capacity 0, durability 5, flavor -1, texture 0, calories 8 +Butterscotch: capacity -1, durability 0, flavor 5, texture 0, calories 6 +Sugar: capacity 0, durability 0, flavor -2, texture 2, calories 1