Day 12
[advent-of-code-18.git] / problems / day12.html
1 <!DOCTYPE html>
2 <html lang="en-us">
3 <head>
4 <meta charset="utf-8"/>
5 <title>Day 12 - Advent of Code 2018</title>
6 <!--[if lt IE 9]><script src="/static/html5.js"></script><![endif]-->
7 <link href='//fonts.googleapis.com/css?family=Source+Code+Pro:300&subset=latin,latin-ext' rel='stylesheet' type='text/css'>
8 <link rel="stylesheet" type="text/css" href="/static/style.css?18"/>
9 <link rel="stylesheet alternate" type="text/css" href="/static/highcontrast.css?0" title="High Contrast"/>
10 <link rel="shortcut icon" href="/favicon.png"/>
11 </head><!--
12
13
14
15
16 Oh, hello! Funny seeing you here.
17
18 I appreciate your enthusiasm, but you aren't going to find much down here.
19 There certainly aren't clues to any of the puzzles. The best surprises don't
20 even appear in the source until you unlock them for real.
21
22 Please be careful with automated requests; I'm not Google, and I can only take
23 so much traffic. Please be considerate so that everyone gets to play.
24
25 If you're curious about how Advent of Code works, it's running on some custom
26 Perl code. Other than a few integrations (auth, analytics, ads, social media),
27 I built the whole thing myself, including the design, animations, prose, and
28 all of the puzzles.
29
30 The puzzles are most of the work; the easiest ones take 3-4 hours each, but the
31 harder ones take 6-8 hours, and a few even longer than that. A lot of effort
32 went into building this thing - I hope you're enjoying playing it as much as I
33 enjoyed making it for you!
34
35 If you'd like to hang out, I'm @ericwastl on Twitter.
36
37 - Eric Wastl
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88 -->
89 <body>
90 <header><div><h1 class="title-global"><a href="/">Advent of Code</a></h1><nav><ul><li><a href="/2018/about">[About]</a></li><li><a href="/2018/events">[Events]</a></li><li><a href="https://teespring.com/adventofcode" target="_blank">[Shop]</a></li><li><a href="/2018/settings">[Settings]</a></li><li><a href="/2018/auth/logout">[Log Out]</a></li></ul></nav><div class="user">Neil Smith <a href="/2018/support" class="supporter-badge" title="Advent of Code Supporter">(AoC++)</a> <span class="star-count">24*</span></div></div><div><h1 class="title-event">&nbsp;<span class="title-event-wrap">{'year':</span><a href="/2018">2018</a><span class="title-event-wrap">}</span></h1><nav><ul><li><a href="/2018">[Calendar]</a></li><li><a href="/2018/support">[AoC++]</a></li><li><a href="/2018/sponsors">[Sponsors]</a></li><li><a href="/2018/leaderboard">[Leaderboard]</a></li><li><a href="/2018/stats">[Stats]</a></li></ul></nav></div></header>
91
92 <div id="sidebar">
93 <div id="sponsor"><div class="quiet">Our <a href="/2018/sponsors">sponsors</a> help make Advent of Code possible:</div><div class="sponsor"><a href="https://www.wearedevelopers.com/world-congress/" target="_blank" onclick="if(ga)ga('send','event','sponsor','click',this.href);" rel="noopener">WeAreDevelopers</a> - Use &quot;AOC-25&quot;, save EUR 25 and join 10^4 devs on June 6-7 at the WeAreDevelopers World Congress in Berlin ticket.get(now)</div></div>
94 </div><!--/sidebar-->
95
96 <main>
97 <article class="day-desc"><h2>--- Day 12: Subterranean Sustainability ---</h2><p>The year 518 is significantly more underground than your history books implied. Either that, or you've arrived in a <span title="It's probably this one. Can never be too sure, though.">vast cavern network</span> under the North Pole.</p>
98 <p>After exploring a little, you discover a long tunnel that contains a row of small pots as far as you can see to your left and right. A few of them contain plants - someone is trying to grow things in these geothermally-heated caves.</p>
99 <p>The pots are numbered, with <code>0</code> in front of you. To the left, the pots are numbered <code>-1</code>, <code>-2</code>, <code>-3</code>, and so on; to the right, <code>1</code>, <code>2</code>, <code>3</code>.... Your puzzle input contains a list of pots from <code>0</code> to the right and whether they do (<code>#</code>) or do not (<code>.</code>) currently contain a plant, the <em>initial state</em>. (No other pots currently contain plants.) For example, an initial state of <code>#..##....</code> indicates that pots <code>0</code>, <code>3</code>, and <code>4</code> currently contain plants.</p>
100 <p>Your puzzle input also contains some notes you find on a nearby table: someone has been trying to figure out how these plants <em>spread</em> to nearby pots. Based on the notes, for each generation of plants, a given pot has or does not have a plant based on whether that pot (and the two pots on either side of it) had a plant in the last generation. These are written as <code>LLCRR =&gt; N</code>, where <code>L</code> are pots to the left, <code>C</code> is the current pot being considered, <code>R</code> are the pots to the right, and <code>N</code> is whether the current pot will have a plant in the next generation. For example:</p>
101 <ul>
102 <li>A note like <code>..#.. =&gt; .</code> means that a pot that contains a plant but with no plants within two pots of it will not have a plant in it during the next generation.</li>
103 <li>A note like <code>##.## =&gt; .</code> means that an empty pot with two plants on each side of it will remain empty in the next generation.</li>
104 <li>A note like <code>.##.# =&gt; #</code> means that a pot has a plant in a given generation if, in the previous generation, there were plants in that pot, the one immediately to the left, and the one two pots to the right, but not in the ones immediately to the right and two to the left.</li>
105 </ul>
106 <p>It's not clear what these plants are for, but you're sure it's important, so you'd like to make sure the current configuration of plants is sustainable by determining what will happen after <em><code>20</code> generations</em>.</p>
107 <p>For example, given the following input:</p>
108 <pre><code>initial state: #..#.#..##......###...###
109
110 ...## => #
111 ..#.. => #
112 .#... => #
113 .#.#. => #
114 .#.## => #
115 .##.. => #
116 .#### => #
117 #.#.# => #
118 #.### => #
119 ##.#. => #
120 ##.## => #
121 ###.. => #
122 ###.# => #
123 ####. => #
124 </code></pre>
125 <p>For brevity, in this example, only the combinations which do produce a plant are listed. (Your input includes all possible combinations.) Then, the next 20 generations will look like this:</p>
126 <pre><code> 1 2 3
127 0 0 0 0
128 0: ...#..#.#..##......###...###...........
129 1: ...#...#....#.....#..#..#..#...........
130 2: ...##..##...##....#..#..#..##..........
131 3: ..#.#...#..#.#....#..#..#...#..........
132 4: ...#.#..#...#.#...#..#..##..##.........
133 5: ....#...##...#.#..#..#...#...#.........
134 6: ....##.#.#....#...#..##..##..##........
135 7: ...#..###.#...##..#...#...#...#........
136 8: ...#....##.#.#.#..##..##..##..##.......
137 9: ...##..#..#####....#...#...#...#.......
138 10: ..#.#..#...#.##....##..##..##..##......
139 11: ...#...##...#.#...#.#...#...#...#......
140 12: ...##.#.#....#.#...#.#..##..##..##.....
141 13: ..#..###.#....#.#...#....#...#...#.....
142 14: ..#....##.#....#.#..##...##..##..##....
143 15: ..##..#..#.#....#....#..#.#...#...#....
144 16: .#.#..#...#.#...##...#...#.#..##..##...
145 17: ..#...##...#.#.#.#...##...#....#...#...
146 18: ..##.#.#....#####.#.#.#...##...##..##..
147 19: .#..###.#..#.#.#######.#.#.#..#.#...#..
148 20: .#....##....#####...#######....#.#..##.
149 </code></pre>
150 <p>The generation is shown along the left, where <code>0</code> is the initial state. The pot numbers are shown along the top, where <code>0</code> labels the center pot, negative-numbered pots extend to the left, and positive pots extend toward the right. Remember, the initial state begins at pot <code>0</code>, which is not the leftmost pot used in this example.</p>
151 <p>After one generation, only seven plants remain. The one in pot <code>0</code> matched the rule looking for <code>..#..</code>, the one in pot <code>4</code> matched the rule looking for <code>.#.#.</code>, pot <code>9</code> matched <code>.##..</code>, and so on.</p>
152 <p>In this example, after 20 generations, the pots shown as <code>#</code> contain plants, the furthest left of which is pot <code>-2</code>, and the furthest right of which is pot <code>34</code>. Adding up all the numbers of plant-containing pots after the 20th generation produces <code><em>325</em></code>.</p>
153 <p><em>After <code>20</code> generations, what is the sum of the numbers of all pots which contain a plant?</em></p>
154 </article>
155 <p>Your puzzle answer was <code>2571</code>.</p><article class="day-desc"><h2 id="part2">--- Part Two ---</h2><p>You realize that 20 generations aren't enough. After all, these plants will need to last another 1500 years to even reach your timeline, not to mention your future.</p>
156 <p><em>After fifty billion (<code>50000000000</code>) generations, what is the sum of the numbers of all pots which contain a plant?</em></p>
157 </article>
158 <p>Your puzzle answer was <code>3100000000655</code>.</p><p class="day-success">Both parts of this puzzle are complete! They provide two gold stars: **</p>
159 <p>At this point, you should <a href="/2018">return to your advent calendar</a> and try another puzzle.</p>
160 <p>If you still want to see it, you can <a href="12/input" target="_blank">get your puzzle input</a>.</p>
161 <p>You can also <span class="share">[Share<span class="share-content">on
162 <a href="https://twitter.com/intent/tweet?text=I%27ve+completed+%22Subterranean+Sustainability%22+%2D+Day+12+%2D+Advent+of+Code+2018&amp;url=https%3A%2F%2Fadventofcode%2Ecom%2F2018%2Fday%2F12&amp;related=ericwastl&amp;hashtags=AdventOfCode" target="_blank">Twitter</a>
163 <a href="http://www.reddit.com/submit?url=https%3A%2F%2Fadventofcode%2Ecom%2F2018%2Fday%2F12&amp;title=I%27ve+completed+%22Subterranean+Sustainability%22+%2D+Day+12+%2D+Advent+of+Code+2018" target="_blank">Reddit</a
164 ></span>]</span> this puzzle.</p>
165 </main>
166
167 <!-- ga -->
168 <script>
169 (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
170 (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
171 m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
172 })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
173 ga('create', 'UA-69522494-1', 'auto');
174 ga('send', 'pageview');
175 </script>
176 <!-- /ga -->
177 </body>
178 </html>