Day 18
authorNeil Smith <neil.git@njae.me.uk>
Fri, 18 Dec 2015 11:17:15 +0000 (11:17 +0000)
committerNeil Smith <neil.git@njae.me.uk>
Fri, 18 Dec 2015 11:17:15 +0000 (11:17 +0000)
SIGNED.md
advent-of-code-18.html [new file with mode: 0644]
advent18.ipynb [new file with mode: 0644]
advent18.txt [new file with mode: 0644]

index a98cc669e9e7745fc5b112cb37d0846a7dbf6d7e..f2a0403cee1f8a9004f5ee9fa5915bacab03963f 100644 (file)
--- a/SIGNED.md
+++ b/SIGNED.md
@@ -3,19 +3,19 @@
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2
 
-iQIcBAABCAAGBQJWc+swAAoJEJPB2e07PgbqiFIQALBGEgy41csOZ63vRZx9Sqr/
-IideywYl/r71msHKGETNcSCoxa2T4m19u3iOEoZyaV9A+QBfM6/rP73GB5jarZWp
-pqxON5vNXslr9HgVAnXV1nw/UcZ/SNvyoS1Jy1dDASu4R3zyEwpuSe2Q3qCyvx+T
-sYxVZlGmsOGUb3sK3YGXRK2wI/6UE5Q3tNW52OyQKFdYsGrUgHgIrEiXGyMcga00
-CfTVWELPY25/Q5Tpvs6UmRB9KJPgk7rfppgOi2nu8a4NH1tCaWG8Glw5ieigIU3g
-5jvR9Gkpu6Duoj3BaHwe6Pe1RDWMVwRgvxkXX8voW3kvyvGVyd6vIssACvSDBxgQ
-R/dNdSjA6lGcp1th/glYsTWHBQdtIlT3L9u+TUzOE9OmSBYwaZ/x7s2eyI62nIzy
-EmTuVbqKg/YGFh8xglPYPeJXvvY+4shOdY+ublnhsav6rfbp8i3C/V6f+uTgFTzG
-cDhvI4DcQhziAW0QIO7UjjI7nS5Dk5QmE2APSaAsGFjSmc54rolSwcZxYLAeoCAj
-9EnrAM93UwVPYpfri8a8fRpj4/DfhroAB9cCECzRGNdz8Fvk8Gao7LZEA/2hBzP9
-RrZKliiTBQxAFRQa6kM73EiMI84x6ccMXPxzUiAsEdv7/dEWAtaBzkQf4LYUfpjM
-0baF8hW1Cmw8P1oZz6ue
-=F3En
+iQIcBAABCAAGBQJWc+s9AAoJEJPB2e07Pgbq/OAQAIyVBhzkraO7tanY5m2n73Kx
+9hks6rBycaaAHkUpR22SSHcCU6hO45cNT+9b2pgupLoKYQCiLrNq6cTjrACUAqX6
+UfVHZIjMwy8F5huYRTiQP2urMc4OaZ9GgZsr++oeCQW3DOty7jz+5It0uuw0BY4R
+ycb9if6XEXfezlqPw16uY7z35i+ZvS9gWfnWEJKTwFJ9i9Q02/mLtuUr97uLMTKv
+FusWDwXQEw0tmgsYb+BUCBPxBBehwdnqOwE/+F2WL6+IxOdKbGG8ZKupnPHMt5aK
+CDHlRBJBDcgeMwct5jlrk+7VrfSyNgPncYBKeYr5vl1jZDqzMES++n4M2CtYq/fM
+1BX6fAHbCUMVhK64jFriIiUCv4qB8CbaVDvro3Khgq5MHRXiTjI38c49n6xdV8c4
+6Dy/WADC0xFi9qJ/DZXRcb/owvmPu0mWpXz/+kfbjivnL9z1YzH2O5B6dAXyL3Mg
+Q/zdM0Z08HG38gcU6OqsaYTysu608gmSFI8SFAJYXHlMFevslHkOX2P78oRDRInK
+qxD25NRor/RfnIjrPSFqF4uLviE/Ybi46xwuqfFYDdlAHgGKoRjcbQrc5lmUkMXW
+r1HdMc7Dmiu2lfS0hS8YVhm2U1HiM7rmrZXl3TnAcNkOcHkIr81s0fXvNUe6rFwB
+XM0pbr/U1BOyM2++oJIX
+=bQXc
 -----END PGP SIGNATURE-----
 
 ```
diff --git a/advent-of-code-18.html b/advent-of-code-18.html
new file mode 100644 (file)
index 0000000..cb20ccc
--- /dev/null
@@ -0,0 +1,242 @@
+<!DOCTYPE html>
+<html lang="en-us">
+<head>
+<meta charset="utf-8"/>
+<title>Day 18 - 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">36*</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 18: Like a GIF For Your Yard ---</h2><p>After the <a href="/day/6">million lights incident</a>, the fire code has gotten stricter: now, at most <span title="This is an outrage!  We're going to the next town hall meeting.">ten thousand lights</span> are allowed.  You arrange them in a 100x100 grid.</p>
+<p>Never one to let you down, Santa again mails you instructions on the ideal lighting configuration.  With so few lights, he says, you'll have to resort to <em>animation</em>.</p>
+<p>Start by setting your lights to the included initial configuration (your puzzle input).  A <code>#</code> means "on", and a <code>.</code> means "off".</p>
+<p>Then, animate your grid in steps, where each step decides the next configuration based on the current one.  Each light's next state (either on or off) depends on its current state and the current states of the eight lights adjacent to it (including diagonals).  Lights on the edge of the grid might have fewer than eight neighbors; the missing ones always count as "off".</p>
+<p>For example, in a simplified 6x6 grid, the light marked <code>A</code> has the neighbors numbered <code>1</code> through <code>8</code>, and the light marked <code>B</code>, which is on an edge, only has the neighbors marked <code>1</code> through <code>5</code>:</p>
+<pre><code>1B5...
+234...
+......
+..123.
+..8A4.
+..765.
+</code></pre>
+<p>The state a light should have next is based on its current state (on or off) plus the <em>number of neighbors that are on</em>:</p>
+<ul>
+<li>A light which is <em>on</em> stays on when <code>2</code> or <code>3</code> neighbors are on, and turns off otherwise.</li>
+<li>A light which is <em>off</em> turns on if exactly <code>3</code> neighbors are on, and stays off otherwise.</li>
+</ul>
+<p>All of the lights update simultaneously; they all consider the same current state before moving to the next.</p>
+<p>Here's a few steps from an example configuration of another 6x6 grid:</p>
+<pre><code>Initial state:
+.#.#.#
+...##.
+#....#
+..#...
+#.#..#
+####..
+
+After 1 step:
+..##..
+..##.#
+...##.
+......
+#.....
+#.##..
+
+After 2 steps:
+..###.
+......
+..###.
+......
+.#....
+.#....
+
+After 3 steps:
+...#..
+......
+...#..
+..##..
+......
+......
+
+After 4 steps:
+......
+......
+..##..
+..##..
+......
+......
+</code></pre>
+<p>After <code>4</code> steps, this example has four lights on.</p>
+<p>In your grid of 100x100 lights, given your initial configuration, <em>how many lights are on after 100 steps</em>?</p>
+</article>
+<p>Your puzzle answer was <code>1061</code>.</p><article class="day-desc"><h2>--- Part Two ---</h2><p>You flip the instructions over; Santa goes on to point out that this is all just an implementation of <a href="https://en.wikipedia.org/wiki/Conway's_Game_of_Life">Conway's Game of Life</a>.  At least, it was, until you notice that something's wrong with the grid of lights you bought: four lights, one in each corner, are <em>stuck on</em> and can't be turned off.  The example above will actually run like this:</p>
+<pre><code>Initial state:
+##.#.#
+...##.
+#....#
+..#...
+#.#..#
+####.#
+
+After 1 step:
+#.##.#
+####.#
+...##.
+......
+#...#.
+#.####
+
+After 2 steps:
+#..#.#
+#....#
+.#.##.
+...##.
+.#..##
+##.###
+
+After 3 steps:
+#...##
+####.#
+..##.#
+......
+##....
+####.#
+
+After 4 steps:
+#.####
+#....#
+...#..
+.##...
+#.....
+#.#..#
+
+After 5 steps:
+##.###
+.##..#
+.##...
+.##...
+#.#...
+##...#
+</code></pre>
+<p>After <code>5</code> steps, this example now has <code>17</code> lights on.</p>
+<p>In your grid of 100x100 lights, given your initial configuration, but with the four corners always in the <em>on</em> state, <em>how many lights are on after 100 steps</em>?</p>
+</article>
+<p>Your puzzle answer was <code>1006</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/18/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+%22Like+a+GIF+For+Your+Yard%22+%2D+Day+18+%2D+Advent+of+Code&amp;url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F18&amp;related=ericwastl&amp;hashtags=AdventOfCode" target="_blank">Twitter</a>
+  <a href="https://plus.google.com/share?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F18" target="_blank">Google+</a>
+  <a href="http://www.reddit.com/submit?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F18&amp;title=I%27ve+completed+%22Like+a+GIF+For+Your+Yard%22+%2D+Day+18+%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/advent18.ipynb b/advent18.ipynb
new file mode 100644 (file)
index 0000000..730bedc
--- /dev/null
@@ -0,0 +1,626 @@
+{
+ "cells": [
+  {
+   "cell_type": "code",
+   "execution_count": 1,
+   "metadata": {
+    "collapsed": false
+   },
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "['.#.#.#', '...##.', '#....#', '..#...', '#.#..#', '####..']"
+      ]
+     },
+     "execution_count": 1,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "pi18 = \"\"\".#.#.#\n",
+    "...##.\n",
+    "#....#\n",
+    "..#...\n",
+    "#.#..#\n",
+    "####..\n",
+    "\"\"\".splitlines()\n",
+    "pi18"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 2,
+   "metadata": {
+    "collapsed": false
+   },
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "(6, 6)"
+      ]
+     },
+     "execution_count": 2,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "rows = len(pi18)\n",
+    "columns = len(pi18[0])\n",
+    "rows, columns"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 3,
+   "metadata": {
+    "collapsed": true
+   },
+   "outputs": [],
+   "source": [
+    "def read_grid(lines):\n",
+    "    grid = {}\n",
+    "    for i, r in enumerate(lines):\n",
+    "        for j, c in enumerate(r):\n",
+    "            if c == '#':\n",
+    "                grid[i, j] = True\n",
+    "    return grid    "
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 4,
+   "metadata": {
+    "collapsed": false
+   },
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "{(0, 1): True,\n",
+       " (0, 3): True,\n",
+       " (0, 5): True,\n",
+       " (1, 3): True,\n",
+       " (1, 4): True,\n",
+       " (2, 0): True,\n",
+       " (2, 5): True,\n",
+       " (3, 2): True,\n",
+       " (4, 0): True,\n",
+       " (4, 2): True,\n",
+       " (4, 5): True,\n",
+       " (5, 0): True,\n",
+       " (5, 1): True,\n",
+       " (5, 2): True,\n",
+       " (5, 3): True}"
+      ]
+     },
+     "execution_count": 4,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "g = read_grid(pi18)\n",
+    "g"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 5,
+   "metadata": {
+    "collapsed": true
+   },
+   "outputs": [],
+   "source": [
+    "def print_grid(grid, rows, columns):\n",
+    "    for r in range(rows):\n",
+    "        for c in range(columns):\n",
+    "            if (r, c) in grid:\n",
+    "                print('#', end='')\n",
+    "            else:\n",
+    "                print('.', end='')\n",
+    "        print('')"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 6,
+   "metadata": {
+    "collapsed": false
+   },
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      ".#.#.#\n",
+      "...##.\n",
+      "#....#\n",
+      "..#...\n",
+      "#.#..#\n",
+      "####..\n"
+     ]
+    }
+   ],
+   "source": [
+    "print_grid(g, rows, columns)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 7,
+   "metadata": {
+    "collapsed": false
+   },
+   "outputs": [],
+   "source": [
+    "def do_generation(grid, rows, columns):\n",
+    "    new_grid = {}\n",
+    "    for r in range(rows):\n",
+    "        for c in range(columns):\n",
+    "            live_neighbours = sum(1\n",
+    "                   for dr in [-1, 0, 1]\n",
+    "                   for dc in [-1, 0, 1]\n",
+    "                   if not (dr == 0 and dc == 0)\n",
+    "                   if (r+dr, c+dc) in grid)\n",
+    "            if (r, c) in grid:\n",
+    "                if live_neighbours in [2, 3]:\n",
+    "                    new_grid[r, c] = True\n",
+    "            else:\n",
+    "                if live_neighbours == 3:\n",
+    "                    new_grid[r, c] = True\n",
+    "    return new_grid"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 8,
+   "metadata": {
+    "collapsed": false
+   },
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "..##..\n",
+      "..##.#\n",
+      "...##.\n",
+      "......\n",
+      "#.....\n",
+      "#.##..\n"
+     ]
+    }
+   ],
+   "source": [
+    "print_grid(do_generation(g, 6, 6), 6, 6)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 9,
+   "metadata": {
+    "collapsed": false
+   },
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      ".#.#.#\n",
+      "...##.\n",
+      "#....#\n",
+      "..#...\n",
+      "#.#..#\n",
+      "####..\n"
+     ]
+    }
+   ],
+   "source": [
+    "print_grid(g, 6, 6)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 10,
+   "metadata": {
+    "collapsed": true
+   },
+   "outputs": [],
+   "source": [
+    "def many_generations(grid, rows, columns, generations):\n",
+    "    for _ in range(generations):\n",
+    "        grid = do_generation(grid, rows, columns)\n",
+    "    return grid"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 11,
+   "metadata": {
+    "collapsed": false
+   },
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "......\n",
+      "......\n",
+      "..##..\n",
+      "..##..\n",
+      "......\n",
+      "......\n"
+     ]
+    }
+   ],
+   "source": [
+    "print_grid(many_generations(g, 6, 6, 4), 6, 6)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 12,
+   "metadata": {
+    "collapsed": false
+   },
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "(100, 100)"
+      ]
+     },
+     "execution_count": 12,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "pi18 = [l.strip() for l in open('advent18.txt').readlines()]\n",
+    "rows = len(pi18)\n",
+    "columns = len(pi18[0])\n",
+    "rows, columns"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 13,
+   "metadata": {
+    "collapsed": false
+   },
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "5076"
+      ]
+     },
+     "execution_count": 13,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "g = read_grid(pi18)\n",
+    "len(g)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 14,
+   "metadata": {
+    "collapsed": false
+   },
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "1061"
+      ]
+     },
+     "execution_count": 14,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "g = many_generations(g, rows, columns, 100)\n",
+    "len(g)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 15,
+   "metadata": {
+    "collapsed": true
+   },
+   "outputs": [],
+   "source": [
+    "def set_corners_on(grid, rows, columns):\n",
+    "    grid[0, 0] = True\n",
+    "    grid[0, columns-1] = True\n",
+    "    grid[rows-1, 0] = True\n",
+    "    grid[rows-1, columns-1] = True\n",
+    "    return grid"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 16,
+   "metadata": {
+    "collapsed": true
+   },
+   "outputs": [],
+   "source": [
+    "def do_generation_2(grid, rows, columns):\n",
+    "    grid = do_generation(grid, rows, columns)\n",
+    "    grid = set_corners_on(grid, rows, columns)\n",
+    "    return grid"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 17,
+   "metadata": {
+    "collapsed": true
+   },
+   "outputs": [],
+   "source": [
+    "def many_generations_2(grid, rows, columns, generations):\n",
+    "    for _ in range(generations):\n",
+    "        grid = do_generation_2(grid, rows, columns)\n",
+    "    return grid"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 18,
+   "metadata": {
+    "collapsed": false
+   },
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "##.#.#\n",
+      "...##.\n",
+      "#....#\n",
+      "..#...\n",
+      "#.#..#\n",
+      "####.#\n"
+     ]
+    }
+   ],
+   "source": [
+    "pi18 = \"\"\".#.#.#\n",
+    "...##.\n",
+    "#....#\n",
+    "..#...\n",
+    "#.#..#\n",
+    "####..\n",
+    "\"\"\".splitlines()\n",
+    "rows = len(pi18)\n",
+    "columns = len(pi18[0])\n",
+    "g = read_grid(pi18)\n",
+    "g = set_corners_on(g, rows, columns)\n",
+    "print_grid(g, rows, columns)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 19,
+   "metadata": {
+    "collapsed": false
+   },
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "#.##.#\n",
+      "####.#\n",
+      "...##.\n",
+      "......\n",
+      "#...#.\n",
+      "#.####\n"
+     ]
+    }
+   ],
+   "source": [
+    "g = do_generation_2(g, 6, 6)\n",
+    "print_grid(g, 6, 6)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 20,
+   "metadata": {
+    "collapsed": false
+   },
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "#..#.#\n",
+      "#....#\n",
+      ".#.##.\n",
+      "...##.\n",
+      ".#..##\n",
+      "##.###\n"
+     ]
+    }
+   ],
+   "source": [
+    "g = do_generation_2(g, 6, 6)\n",
+    "print_grid(g, 6, 6)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 21,
+   "metadata": {
+    "collapsed": false
+   },
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "##.#.#\n",
+      "...##.\n",
+      "#....#\n",
+      "..#...\n",
+      "#.#..#\n",
+      "####.#\n"
+     ]
+    }
+   ],
+   "source": [
+    "pi18 = \"\"\".#.#.#\n",
+    "...##.\n",
+    "#....#\n",
+    "..#...\n",
+    "#.#..#\n",
+    "####..\n",
+    "\"\"\".splitlines()\n",
+    "rows = len(pi18)\n",
+    "columns = len(pi18[0])\n",
+    "g = read_grid(pi18)\n",
+    "g = set_corners_on(g, rows, columns)\n",
+    "print_grid(g, rows, columns)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 22,
+   "metadata": {
+    "collapsed": false
+   },
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "##.###\n",
+      ".##..#\n",
+      ".##...\n",
+      ".##...\n",
+      "#.#...\n",
+      "##...#\n"
+     ]
+    }
+   ],
+   "source": [
+    "print_grid(many_generations_2(g, 6, 6, 5), 6, 6)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 23,
+   "metadata": {
+    "collapsed": false
+   },
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "(100, 100)"
+      ]
+     },
+     "execution_count": 23,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "pi18 = [l.strip() for l in open('advent18.txt').readlines()]\n",
+    "rows = len(pi18)\n",
+    "columns = len(pi18[0])\n",
+    "rows, columns"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 24,
+   "metadata": {
+    "collapsed": false
+   },
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "5078"
+      ]
+     },
+     "execution_count": 24,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "g = read_grid(pi18)\n",
+    "g = set_corners_on(g, rows, columns)\n",
+    "len(g)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 25,
+   "metadata": {
+    "collapsed": false
+   },
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "1006"
+      ]
+     },
+     "execution_count": 25,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "g = many_generations_2(g, rows, columns, 100)\n",
+    "len(g)"
+   ]
+  },
+  {
+   "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/advent18.txt b/advent18.txt
new file mode 100644 (file)
index 0000000..dc69240
--- /dev/null
@@ -0,0 +1,100 @@
+#..####.##..#...#..#...#...###.#.#.#..#....#.##..#...##...#..#.....##..#####....#.##..##....##.#....
+.#..#..#..#.###...##..#.##.....#...#..##....#####.##............####.#..######..#.#.##.#...#..#...##
+#.....##.##.##.#..##.#..###...#.#.#..##..###.####.####.#.####.#...##.#..###.........#.###...#....###
+#.###..#######..##..#.....##.#.#.###.#.##..#.##..##.##.#.##...###.#...#.#####.#.##..#.#####..#.#####
+#.##.##.###.##..###.#.##.##...##.#.#..##..###.########.#.####..####...#####...#..#...##....##.##.##.
+..#.#.#.#..#.#.###....###...#...#.##..####.###.....#.####.###.###.#......#.#.###..#..#.#....#.#####.
+...#.###.#....#.###...#.#.#...#...#.#####....#....#...#####..#..#.#..######..#.##.#.##.#..###.#...##
+.###...#...#.#..#.#.####.#...#.....##...###.#....#..##.###....#.##....###..#.#####...###.#.##.####..
+#.#....##.#.....#####.#.##..#######.#.####..###.##.#####.##.#...###...#.#...###..#...#.#.###.###.###
+...##.##.....##..#.##...#.#...#...#.#####.#...#.#.#.#####.##.#...#.#..##.##..#...#....####..###.###.
+#..#....######...#...###.#....#####....#.#.#....#....#.#######.#####..#....#....#.##..#.##.###..#...
+#####.#.######.#.#####.#..##..##..####..#....#...#######....##..##.#..###..###.###..###...#...######
+#...##..##...###....##..##.##..#.#.#.#....##.#.......###..###..###...###..##.##.##.#.#.#..#.#..#..#.
+..###....##.###..#.#..########...###...##..#######....##..###..#####.##.#....###..##.##.##.#...##.#.
+###..#.#..#.#.##.##...##.....#..###.#..##.##.#....##.#.######..##..#.#.##.###...#..####...#.#..#.###
+.######....#..##..#.####.##..#.#..#.#..#....#..##.#..#.#...####..#....#.####.#.###.#...####.#...#.#.
+#.######.##..###.###..#..###.#...#..#...#...###.##....#.#......#...#.##.#.###..#.#####.#.#..###..#.#
+...#..#...####..###.########.....###.###.#..##.##....######..#..#.....#.##.##.#..##..#..##...#..#..#
+#..#..##..#.#.########.##.#.####..#.#####.#.###.##....###..##..#.#.###..#.##..##.##.####...######.##
+.######.###....#...##...#..#....##..#.#...###.######.##...#....##.##.#.#.##..#...###.###.#....#..##.
+####.#.##..##.##.###...#.###.##..##....###..####.##..#.#.##..###.#..##...####...#..####.#.#..##...#.
+.#.#..#.....##...#..#...#.#...#.#.##..#....#..#......#####.#######....#.#..#..###..##.#.########..##
+.##.#..#..##..#..####.#...####...#...#..##.#..###.#..######..#.#...###.##...#..#####..##.#..##.#.##.
+.###..##.##.##....###.###..#.#...##.#.#...#.#######.####..#..###.#######.#...#.#...#.##...#..####..#
+##.########..#..#....#.###..##.##.#.##.#..#......####..##.##.#..####..#####..#.....#####.###..#.#.#.
+.#..####..##.#.#..#####.##..#..#.#....#.#####.#####...######........##.##..##.#.#.###..#.#.#.#..##.#
+.##..##..#.######..###....#.#.###.#........#..###..#.########.....#.##...#.....#..#...##...#..#.###.
+##.##.#..####....####.#######.....#.#.#...#.######.#.....####.####...###..####.##.##....###..#..#...
+#.#..####...#......#...###...##....##.#######..#.###.#...###.##.##...####..#.####..#......##..#####.
+.#.#...##...#....#.####.##.....#....#.#.#######..###.#.....#.....####...##...#.#.##.####..##.###.#.#
+####.#.#.####...#...####.#.....#.#######.#.......####......###..###.#...######..#.##.#.##..#..##..##
+..##.###..#..####..####.......######.##..#.....##.##...##.##......#.###..###...#.##.#####.#.######.#
+.###..####.###..#..#.......#.##...##...##.######.....#..####.#......#.#...#...#...###...#.#.##..####
+.####....##.##.#.....##.###.####.#.......#.......#.#..#.#.#.....###.#.#####.#..#.#.#####.#####.###.#
+.##.#.###.#####..#..#....###.#.#.#..#..###..##..####..##.###....#..####.####.#..###.#..######.######
+####.#.....##..###....#.....#.##.#.##..##..########.#####..###.####....##.....######.#.#.##.......#.
+#.#.##.....#.....##.###.#..#.##.##....#..##....##.#.###.##.#..#..##.##.###.#..##.###...##..###.#####
+#.###.#.#.#.#.#.#.#...#..#.###..####.##...#..####.###....#..#..##.#....####..##.##....#.#.##.##....#
+...######....#..####...#.#..#.#.#..#.##.#.#.......#..#......##..#...#..#..##...##.#...#.#.#...##.##.
+.#####..#...####....#..###..##....#####..###.#.#...###..###.###..##...#......#...#...#.#.#...#.##..#
+......#####.#...#.#.#.##..#.###..##..#.#...###..###....##..#####..#######.#..#.###....###...##.#..#.
+..##.########.##..#....##.#...##.##.#.#..#.##..#.#.#.##....#.#.#.#.##....##....#....#####.##..#.##.#
+####...#....##.#.###......##.##.#..##...#..#####..#.#....##..#####...#.#.##...#.####.####..##.######
+.##.###.##.#...#.#....###.#######...##...##..#..##.###.#.####..#..###......#.#.##.#.#....#..##...#..
+.#.###.#.###.###.#.##.#..#......####.##...#..##.#..####.....#...#.###.##.##.#..#.##..#.###......#..#
+...##.####......#.#.#..###..#....###....#.##.#####..#..#..#...#.#.###...#.#.#.##....###.####..###.#.
+##..#.#.#.#....####...#.##.###..####....#..#####.######..#.##.##..#####.#.....#.#...##.#.##.##.#.#..
+#..##.#.#.#.###.#.#.###...#.#...##..#..#.#.#.##..###...#..##.#..#.#.#..#.....#.######.#.###..###.#..
+....#.#.##.###.##...#.##.#....#..##.#..##...#...#.##.####...##..####.#.........#..##..#...#...##.#..
+.##.......##...###.##.#.##.###.##.#..#..#..####...#...#....#####...###..##..#..#..##...#....#..#####
+..####..#...#...#..###....##.#.#####..#..#.....#......#...#.......##....####...##....##.##.#.#####.#
+##.#.#.#..##..##..#.####.##.##.###.#...###.#....#.....#.###...#######..###.####.###.####.##...##.#..
+..#.#...##.#....#..#..##.####.....#.#.#...#..#..###.#..###.#####.#.#####.#.#.#.#.###.##.###..#....##
+.###.#...#....###..#...####....####..#.##..#..##.###..#.#.#.#..#...###.#.#...#......#...#.##.##.#...
+..####.####.##.#.##....#...##....#..#....#..###..#...#..###.#####.....#####..##.#.#.#.#.#.##.####...
+...##.#.##.####..##.###..#.#.#.#.#.#.#..###...#.##..#.####.##...#.#.##......###..#...###....#.#.###.
+##...##..#.#.##..#.#.#....#.####.......#.#.#######.#..#....#.###.#...###.##....###.#.#..#.#.##.####.
+...##.......######.....##....#...#..#.##.###.#..#.##.###.#.###.#.#.#...#.#...##.##.##..#.##########.
+###..#....#.#.....#....###.#...##.......##.#.#..#.#...########......###..##.#..#..####.##..####...#.
+......##.###.#.###.....#..#...#.#......##....#....#........#..#...##.##.....#...##.##.........##....
+.##.##.#.#...#....######..##....##..##.#.#.##.#.##..##...#..###......##......#.#....#.#.#.......###.
+.......#.##..##.#...#.##..#..#####.#..#.######.........###.#####.####.#...##...........##...##..####
+#......#.#..#...#...##..#.#.###.##.##.#.#..#.###.##.#..###..#.###..#...###.##..###..#...#..###...#..
+####.##..#####..####.#...#..#..###..##.#.#...#...#...#.##.####.##.###....###...#.#.#..####.######.##
+.....#..####...#.#.#.####..####..##.###......#.....########.#...#.#..#..#...#.###..##.#####..###.###
+.#######.#.##..###.#...###.#####............##.###...#.##.#.##..##.#.#..#.######..######..#..#..####
+...##..#.####...#..#.#.##.#....#.####..#..###.###..#.#...#....##.##.#......##..##..#.#.#.###..#..#..
+........#...#.##.#.#..#....####....#.##...###..####...###.#.#..######..###..##.#####.###.###.#.#...#
+##......##.#..###.####.##.#.###.#.......#.##..####..#.###.##..##..##...##...#.###...#.#..#..#.#####.
+##..#.#.....##.####.#..##.#.##.#.#...#...#.#...####.#.#.##...##....##.###..###.####.#...#.###..#####
+.#####.####.####.####.#.##.##......###....###.####...###...#...#..#.##.#.#####.###..##.#..###...##..
+.#...#..##...##...#....#.#.#..##..#.##..#.###.#.###..###.#.#.###.#....#######.####.##..#..#...####..
+..##.##..#.##..#.#.###..#.##.########...####.#.###.##..#..###.###...##..##.#..#.######.##.#....###.#
+##.#####.###.##.#.##.##.##.###..##..##..#.#.#.#.####..#......#.#.#.#.#.#.##...#####.####...#.#...#.#
+.#..###..##.#####.#.##.#..##...##..##...#####.#.####..#...##.....######.#.#...##.#..#######.###.###.
+#.#..##.#.#####.#.#.....###.###.#..##.#####....#.###.##.##.#.#..##..#.#....#######.###.#.#.....#.###
+....###...#.###.####....###.....##....#####.##.###.###.##.##.##.#..###..######...####.#.#..####..#..
+###.....#..####..#.####..#..#...##.##..##.######.####.....#...##....#..#.##.#####..###.##.#.####...#
+.##.##.#...#..####...##.##.###...#...#..#.#.#####.....####...#.#.#..#.####...####.#...###.#......###
+###.##....#.#.#...#.###....####..##...##.##.##.#..#...####..#..#..##...#####.####.####...##.#..###.#
+..####.....##..###.#.#.###.########..#...#.##..#.#.#.......#.##.#..#...####.##.#..#.######..#.#...#.
+#.#.##.#.#.##.#....##......##......#######.#..#.##...##..#.#.###...#.#..#..###...#..###.....##.....#
+..#.##.#.##.#.##..##.....#.#..#.#..#...##..#..#.#....###.#####....####.####..#####.##.###...#..###.#
+#....#.###..#..########.###..#.#.#.##...##.#..##.###..#..#..#.#.##..###...###.#.##..#.##.#..#.#.####
+#.......#######......#...#...##.##...###.#....##.#..#....####.#.##.###...#.#####...##.###........##.
+.##.####.....###.##......####.###.########..#.####..#.##.#.####.....#...#.##....#######.##..#......#
+#.#.##.##....##..##.#.###..#.##.#..#..#.#..##.....###..###.##.##.####.##.#.#.##...####..#.#..##.#.#.
+...##.#.#.#...###.#.......#.#.....#.#...##....##.##.##.####...#.#..#..#..#.#.##.#..#.#.#....###..#.#
+....#.#.###.#####.##..###..##..#...#.##.#......##.####.#..####.#.##..####.#.#...##..#####..##.#.#...
+..###.#.##..#....#..#.#.....##.#####..##....#.#...#.##..##.#.#..#...##.##..##..##....#...#..#..#..##
+##.#.##.#...#.###.##.##.##.##..##.##...#..##.#..#######.#..#...#.#.##..#....##.#..####.###........#.
+.##.#..#.....#####..##.#.#.#.#..###.#######.###.###....##....#.#.#.###....###.#..#.#....#.#..###...#
+...###.#.#.###..#...#..###.######..##.#.#..#...####.#####.##..#..###...#..#..#..###..##.#.#...#.###.
+#......#.#..#..##.##.#.##.#.###.#.##.#.#..#....#.##..#..##..##.#.#.#....##.###.###.####.#.#####...##
+...#.##..#.######.......#.#.###.....#####....##.#.#.###........#.#.###.#.#########.##.##.#..##..#...
+##..###..###....####.##.##..##.###....####..##...####.####..####..###.####..##.#...###.#####.##.##.#
+###...##.#.#.#####..#..#####...##.#...#.#.###.#..##..###.##.#.#.....####.##.#..##.###.#...##.##...##
+...#.#.##.##..##....#..#.#####.##.###..#.#.#........####.###.##....##....####..#.#....#.#.#.###..#.#
+..#.#.#.#.###...#....##..######.##....#.#.##..###..#.#.###..#.##..#.#.###......#..#..#.####..#...##.
+.....####.#.....###.#.##.#..##.#..###.#####.#..##...###.#..###..#..##....###.#..##.#..#.##.#..#...##
\ No newline at end of file