Started on day 15
authorNeil Smith <neil.git@njae.me.uk>
Tue, 15 Dec 2015 09:29:14 +0000 (09:29 +0000)
committerNeil Smith <neil.git@njae.me.uk>
Tue, 15 Dec 2015 09:29:14 +0000 (09:29 +0000)
SIGNED.md
advent-of-code-14.html [new file with mode: 0644]
advent15.ipynb [new file with mode: 0644]
advent15.txt [new file with mode: 0644]

index f17a89cfdcd31d625f06a46220dd93b33a9c74ee..d5e829ea9aca0c40576a54b5dc6ec91b1dd5850f 100644 (file)
--- 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 (file)
index 0000000..3486508
--- /dev/null
@@ -0,0 +1,145 @@
+<!DOCTYPE html>
+<html lang="en-us">
+<head>
+<meta charset="utf-8"/>
+<title>Day 14 - Advent of Code</title>
+<!--[if lt IE 9]><script src="/static/html5.js"></script><![endif]-->
+<link href='//fonts.googleapis.com/css?family=Source+Code+Pro:300&subset=latin,latin-ext' rel='stylesheet' type='text/css'>
+<link rel="stylesheet" type="text/css" href="/static/style.css?3"/>
+<link rel="shortcut icon" href="/favicon.ico?2"/>
+</head><!--
+
+
+
+
+Oh, hello!  Funny seeing you here.
+
+I appreciate your enthusiasm, but you aren't going to find much down here.
+There certainly aren't clues to any of the puzzles.  You do risk spoiling a few
+surprises for yourself, though.  Best to play the normal way and discover
+everything as it was intended, I think.  The best surprises don't even appear
+in the source until you unlock them for real.
+
+Please be careful with automated requests; I'm not Google, and I can only take
+so much traffic.  Please be considerate so that everyone gets to play.
+
+If you're curious about how Advent of Code works, it's running on some custom
+Perl code. Other than a few integrations (auth, analytics, ads, social media),
+I built the whole thing myself, including the design, animations, prose, and
+all of the puzzles.
+
+The puzzles probably took the longest; the easiest ones were around 45 minutes
+each, but the harder ones took 2-3 hours, some even longer than that. A lot of
+effort went into building this thing - I hope you're enjoying playing it as
+much as I enjoyed making it for you!
+
+If you'd like to hang out, I'm @ericwastl on Twitter.
+
+- Eric Wastl
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+-->
+<body>
+<header><h1><a href="/">Advent of Code</a></h1><div class="user">Neil Smith <span class="star-count">28*</span></div><nav><ul><li><a href="/about">[About]</a></li><li><a href="/stats">[Stats]</a></li><li><a href="/leaderboard">[Leaderboard]</a></li><li><a href="/settings">[Settings]</a></li><li><a href="/auth/logout">[Log out]</a></li></ul></nav></header>
+
+<div id="ad">
+<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
+<!-- Advent of Code Wide Skyscraper -->
+<ins class="adsbygoogle"
+     style="display:inline-block;width:160px;height:600px"
+     data-ad-client="ca-pub-9420604735624631"
+     data-ad-slot="8014013294"></ins>
+<script>
+(adsbygoogle = window.adsbygoogle || []).push({});
+</script>
+</div><!--/ad-->
+
+<main>
+<article class="day-desc"><h2>--- Day 14: Reindeer Olympics ---</h2><p>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.</p>
+<p>Reindeer can only either be <em>flying</em> (always at their top speed) or <em>resting</em> (not moving at all), and always spend whole seconds in either state.</p>
+<p>For example, suppose you have the following Reindeer:</p>
+<ul>
+<li>Comet can fly <em>14 km/s for 10 seconds</em>, but then must rest for <em>127 seconds</em>.</li>
+<li>Dancer can fly <em>16 km/s for 11 seconds</em>, but then must rest for <em>162 seconds</em>.</li>
+</ul>
+<p>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.</p>
+<p>In this example, after the 1000th second, both reindeer are resting, and Comet is in the lead at <em><code>1120</code></em> km (poor Dancer has only gotten <code>1056</code> km by that point).  So, in this situation, Comet would win (if the race ended at 1000 seconds).</p>
+<p>Given the descriptions of each reindeer (in your puzzle input), after exactly <code>2503</code> seconds, <em>what distance has the winning reindeer traveled</em>?</p>
+</article>
+<p>Your puzzle answer was <code>2655</code>.</p><article class="day-desc"><h2>--- Part Two ---</h2><p>Seeing how reindeer move in bursts, Santa decides he's not pleased with the old scoring system.</p>
+<p>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 <span title="It also risks choosing a duration that isn't coprime with the cycle times of each reindeer.">entirely ridiculous</span>.</p>
+<p>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.</p>
+<p>After the 1000th second, Dancer has accumulated <em><code>689</code></em> points, while poor Comet, our old champion, only has <code>312</code>.  So, with the new scoring system, Dancer would win (if the race ended at 1000 seconds).</p>
+<p>Again given the descriptions of each reindeer (in your puzzle input), after exactly <code>2503</code> seconds, <em>how many points does the winning reindeer have</em>?</p>
+</article>
+<p>Your puzzle answer was <code>1059</code>.</p><p class="day-success">Both parts of this puzzle are complete! They provide two gold stars: **</p>
+<p>At this point, you should <a href="/">return to your advent calendar</a> and try another puzzle.</p>
+<p>If you still want to see it, you can <a href="/day/14/input" target="_blank">get your puzzle input</a>.</p>
+<p>You can also <span class="share">[Share<span class="share-content">on
+  <a href="https://twitter.com/intent/tweet?text=I%27ve+completed+%22Reindeer+Olympics%22+%2D+Day+14+%2D+Advent+of+Code&amp;url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F14&amp;related=ericwastl&amp;hashtags=AdventOfCode" target="_blank">Twitter</a>
+  <a href="https://plus.google.com/share?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F14" target="_blank">Google+</a>
+  <a href="http://www.reddit.com/submit?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F14&amp;title=I%27ve+completed+%22Reindeer+Olympics%22+%2D+Day+14+%2D+Advent+of+Code" target="_blank">Reddit</a
+></span>]</span>
+ this puzzle.</p>
+</main>
+
+<!-- ga -->
+<script>
+(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
+(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
+m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
+})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
+ga('create', 'UA-69522494-1', 'auto');
+ga('send', 'pageview');
+</script>
+<!-- /ga -->
+</body>
+</html>
diff --git a/advent15.ipynb b/advent15.ipynb
new file mode 100644 (file)
index 0000000..ebc895f
--- /dev/null
@@ -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<ipython-input-23-95769c86abac>\u001b[0m in \u001b[0;36m<module>\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 (file)
index 0000000..634c6a5
--- /dev/null
@@ -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