Taking advantage of a neat trick for using $ rather than a lambda
[advent-of-code-17.git] / problems / day21.html
1 <!DOCTYPE html>
2 <html lang="en-us">
3 <head>
4 <meta charset="utf-8"/>
5 <title>Day 21 - Advent of Code 2017</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?12"/>
9 <link rel="stylesheet alternate" type="text/css" href="/static/highcontrast.css?0" title="High Contrast"/>
10 <link rel="shortcut icon" href="/favicon.ico?2"/>
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 probably took the longest; the easiest ones took an hour or two
31 each, but the harder ones took 4-5 hours, and a few even longer than that. A
32 lot of effort went into building this thing - I hope you're enjoying playing it
33 as much as I 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="/2017/about">[About]</a></li><li><a href="/2017/support">[AoC++]</a></li><li><a href="/2017/events">[Events]</a></li><li><a href="/2017/settings">[Settings]</a></li><li><a href="/2017/auth/logout">[Log Out]</a></li></ul></nav><div class="user">Neil Smith <span class="supporter">(AoC++)</span> <span class="star-count">42*</span></div></div><div><h1 class="title-event">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="title-event-wrap"></span><a href="/2017">2017</a><span class="title-event-wrap"></span></h1><nav><ul><li><a href="/2017">[Calendar]</a></li><li><a href="/2017/leaderboard">[Leaderboard]</a></li><li><a href="/2017/stats">[Stats]</a></li><li><a href="/2017/sponsors">[Sponsors]</a></li></ul></nav></div></header>
91
92 <div id="sidebar">
93 <div id="sponsor"><div class="quiet">Our <a href="/2017/sponsors">sponsors</a> help make Advent of Code possible:</div><p><a href="http://kx.com/" target="_blank" onclick="if(ga)ga('send','event','sponsor','click',this.href);" rel="noopener">Kx Systems</a> - kdb+, the in-memory time series technology standard</p></div>
94 <p class="quiet">By popular demand, there are now AoC-themed objects available (until Jan. 3rd)! Get them shipped <a href="https://teespring.com/advent-of-code" target="_blank">from the US</a> or <a href="https://teespring.com/advent-of-code-eu" target="_blank">from Europe</a>.</p>
95
96 </div><!--/sidebar-->
97
98 <main>
99 <article class="day-desc"><h2>--- Day 21: Fractal Art ---</h2><p>You find a program trying to generate some art. It uses a strange process that involves <span title="This technique is also often used on TV.">repeatedly enhancing</span> the detail of an image through a set of rules.</p>
100 <p>The image consists of a two-dimensional square grid of pixels that are either on (<code>#</code>) or off (<code>.</code>). The program always begins with this pattern:</p>
101 <pre><code>.#.
102 ..#
103 ###
104 </code></pre>
105 <p>Because the pattern is both <code>3</code> pixels wide and <code>3</code> pixels tall, it is said to have a <em>size</em> of <code>3</code>.</p>
106 <p>Then, the program repeats the following process:</p>
107 <ul>
108 <li>If the size is evenly divisible by <code>2</code>, break the pixels up into <code>2x2</code> squares, and convert each <code>2x2</code> square into a <code>3x3</code> square by following the corresponding <em>enhancement rule</em>.</li>
109 <li>Otherwise, the size is evenly divisible by <code>3</code>; break the pixels up into <code>3x3</code> squares, and convert each <code>3x3</code> square into a <code>4x4</code> square by following the corresponding <em>enhancement rule</em>.</li>
110 </ul>
111 <p>Because each square of pixels is replaced by a larger one, the image gains pixels and so its <em>size</em> increases.</p>
112 <p>The artist's book of enhancement rules is nearby (your puzzle input); however, it seems to be missing rules. The artist explains that sometimes, one must <em>rotate</em> or <em>flip</em> the input pattern to find a match. (Never rotate or flip the output pattern, though.) Each pattern is written concisely: rows are listed as single units, ordered top-down, and separated by slashes. For example, the following rules correspond to the adjacent patterns:</p>
113 <pre><code>../.# = ..
114 .#
115
116 .#.
117 .#./..#/### = ..#
118 ###
119
120 #..#
121 #..#/..../#..#/.##. = ....
122 #..#
123 .##.
124 </code></pre>
125 <p>When searching for a rule to use, rotate and flip the pattern as necessary. For example, all of the following patterns match the same rule:</p>
126 <pre><code>.#. .#. #.. ###
127 ..# #.. #.# ..#
128 ### ### ##. .#.
129 </code></pre>
130 <p>Suppose the book contained the following two rules:</p>
131 <pre><code>../.# => ##./#../...
132 .#./..#/### => #..#/..../..../#..#
133 </code></pre>
134 <p>As before, the program begins with this pattern:</p>
135 <pre><code>.#.
136 ..#
137 ###
138 </code></pre>
139 <p>The size of the grid (<code>3</code>) is not divisible by <code>2</code>, but it is divisible by <code>3</code>. It divides evenly into a single square; the square matches the second rule, which produces:</p>
140 <pre><code>#..#
141 ....
142 ....
143 #..#
144 </code></pre>
145 <p>The size of this enhanced grid (<code>4</code>) is evenly divisible by <code>2</code>, so that rule is used. It divides evenly into four squares:</p>
146 <pre><code>#.|.#
147 ..|..
148 --+--
149 ..|..
150 #.|.#
151 </code></pre>
152 <p>Each of these squares matches the same rule (<code>../.# => ##./#../...</code>), three of which require some flipping and rotation to line up with the rule. The output for the rule is the same in all four cases:</p>
153 <pre><code>##.|##.
154 #..|#..
155 ...|...
156 ---+---
157 ##.|##.
158 #..|#..
159 ...|...
160 </code></pre>
161 <p>Finally, the squares are joined into a new grid:</p>
162 <pre><code>##.##.
163 #..#..
164 ......
165 ##.##.
166 #..#..
167 ......
168 </code></pre>
169 <p>Thus, after <code>2</code> iterations, the grid contains <code>12</code> pixels that are <em>on</em>.</p>
170 <p><em>How many pixels stay on</em> after <code>5</code> iterations?</p>
171 </article>
172 <p>Your puzzle answer was <code>158</code>.</p><article class="day-desc"><h2>--- Part Two ---</h2><p><em>How many pixels stay on</em> after <code>18</code> iterations?</p>
173 </article>
174 <p>Your puzzle answer was <code>2301762</code>.</p><p class="day-success">Both parts of this puzzle are complete! They provide two gold stars: **</p>
175 <p>At this point, you should <a href="/2017">return to your advent calendar</a> and try another puzzle.</p>
176 <p>If you still want to see it, you can <a href="21/input" target="_blank">get your puzzle input</a>.</p>
177 <p>You can also <span class="share">[Share<span class="share-content">on
178 <a href="https://twitter.com/intent/tweet?text=I%27ve+completed+%22Fractal+Art%22+%2D+Day+21+%2D+Advent+of+Code+2017&amp;url=http%3A%2F%2Fadventofcode%2Ecom%2F2017%2Fday%2F21&amp;related=ericwastl&amp;hashtags=AdventOfCode" target="_blank">Twitter</a>
179 <a href="https://plus.google.com/share?url=http%3A%2F%2Fadventofcode%2Ecom%2F2017%2Fday%2F21" target="_blank">Google+</a>
180 <a href="http://www.reddit.com/submit?url=http%3A%2F%2Fadventofcode%2Ecom%2F2017%2Fday%2F21&amp;title=I%27ve+completed+%22Fractal+Art%22+%2D+Day+21+%2D+Advent+of+Code+2017" target="_blank">Reddit</a
181 ></span>]</span> this puzzle.</p>
182 </main>
183
184 <!-- ga -->
185 <script>
186 (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
187 (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
188 m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
189 })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
190 ga('create', 'UA-69522494-1', 'auto');
191 ga('send', 'pageview');
192 </script>
193 <!-- /ga -->
194 </body>
195 </html>