Updated readme
[advent-of-code-18.git] / problems / day05.html
1 <!DOCTYPE html>
2 <html lang="en-us">
3 <head>
4 <meta charset="utf-8"/>
5 <title>Day 5 - 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?17"/>
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">10*</span></div></div><div><h1 class="title-event">&nbsp;&nbsp;&nbsp;<span class="title-event-wrap">int y=</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.novetta.com/our-story/" target="_blank" onclick="if(ga)ga('send','event','sponsor','click',this.href);" rel="noopener">Novetta</a> - TS/SCI engineers &amp; data scientists developing mission-critical disruptive technologies by day, helping Santa by night.</div></div>
94 </div><!--/sidebar-->
95
96 <main>
97 <article class="day-desc"><h2>--- Day 5: Alchemical Reduction ---</h2><p>You've managed to sneak in to the prototype suit manufacturing lab. The Elves are making decent progress, but are still struggling with the suit's size reduction capabilities.</p>
98 <p>While the very latest in 1518 alchemical technology might have solved their problem eventually, you can do better. You scan the chemical composition of the suit's material and discover that it is formed by extremely long <a href="https://en.wikipedia.org/wiki/Polymer">polymers</a> (one of which is <span title="I've always wanted a polymer!">available</span> as your puzzle input).</p>
99 <p>The polymer is formed by smaller <em>units</em> which, when triggered, react with each other such that two adjacent units of the same type and opposite polarity are destroyed. Units' types are represented by letters; units' polarity is represented by capitalization. For instance, <code>r</code> and <code>R</code> are units with the same type but opposite polarity, whereas <code>r</code> and <code>s</code> are entirely different types and do not react.</p>
100 <p>For example:</p>
101 <ul>
102 <li>In <code>aA</code>, <code>a</code> and <code>A</code> react, leaving nothing behind.</li>
103 <li>In <code>abBA</code>, <code>bB</code> destroys itself, leaving <code>aA</code>. As above, this then destroys itself, leaving nothing.</li>
104 <li>In <code>abAB</code>, no two adjacent units are of the same type, and so nothing happens.</li>
105 <li>In <code>aabAAB</code>, even though <code>aa</code> and <code>AA</code> are of the same type, their polarities match, and so nothing happens.</li>
106 </ul>
107 <p>Now, consider a larger example, <code>dabAcCaCBAcCcaDA</code>:</p>
108 <pre><code>dabA<em>cC</em>aCBAcCcaDA The first 'cC' is removed.
109 dab<em>Aa</em>CBAcCcaDA This creates 'Aa', which is removed.
110 dabCBA<em>cCc</em>aDA Either 'cC' or 'Cc' are removed (the result is the same).
111 dabCBAcaDA No further actions can be taken.
112 </code></pre>
113 <p>After all possible reactions, the resulting polymer contains <em>10 units</em>.</p>
114 <p><em>How many units remain after fully reacting the polymer you scanned?</em> <span class="quiet">(Note: in this puzzle and others, the input is large; if you copy/paste your input, make sure you get the whole thing.)</span></p>
115 </article>
116 <p>Your puzzle answer was <code>9060</code>.</p><article class="day-desc"><h2 id="part2">--- Part Two ---</h2><p>Time to improve the polymer.</p>
117 <p>One of the unit types is causing problems; it's preventing the polymer from collapsing as much as it should. Your goal is to figure out which unit type is causing the most problems, remove all instances of it (regardless of polarity), fully react the remaining polymer, and measure its length.</p>
118 <p>For example, again using the polymer <code>dabAcCaCBAcCcaDA</code> from above:</p>
119 <ul>
120 <li>Removing all <code>A</code>/<code>a</code> units produces <code>dbcCCBcCcD</code>. Fully reacting this polymer produces <code>dbCBcD</code>, which has length 6.</li>
121 <li>Removing all <code>B</code>/<code>b</code> units produces <code>daAcCaCAcCcaDA</code>. Fully reacting this polymer produces <code>daCAcaDA</code>, which has length 8.</li>
122 <li>Removing all <code>C</code>/<code>c</code> units produces <code>dabAaBAaDA</code>. Fully reacting this polymer produces <code>daDA</code>, which has length 4.</li>
123 <li>Removing all <code>D</code>/<code>d</code> units produces <code>abAcCaCBAcCcaA</code>. Fully reacting this polymer produces <code>abCBAc</code>, which has length 6.</li>
124 </ul>
125 <p>In this example, removing all <code>C</code>/<code>c</code> units was best, producing the answer <em>4</em>.</p>
126 <p><em>What is the length of the shortest polymer you can produce</em> by removing all units of exactly one type and fully reacting the result?</p>
127 </article>
128 <p>Your puzzle answer was <code>6310</code>.</p><p class="day-success">Both parts of this puzzle are complete! They provide two gold stars: **</p>
129 <p>At this point, you should <a href="/2018">return to your advent calendar</a> and try another puzzle.</p>
130 <p>If you still want to see it, you can <a href="5/input" target="_blank">get your puzzle input</a>.</p>
131 <p>You can also <span class="share">[Share<span class="share-content">on
132 <a href="https://twitter.com/intent/tweet?text=I%27ve+completed+%22Alchemical+Reduction%22+%2D+Day+5+%2D+Advent+of+Code+2018&amp;url=https%3A%2F%2Fadventofcode%2Ecom%2F2018%2Fday%2F5&amp;related=ericwastl&amp;hashtags=AdventOfCode" target="_blank">Twitter</a>
133 <a href="http://www.reddit.com/submit?url=https%3A%2F%2Fadventofcode%2Ecom%2F2018%2Fday%2F5&amp;title=I%27ve+completed+%22Alchemical+Reduction%22+%2D+Day+5+%2D+Advent+of+Code+2018" target="_blank">Reddit</a
134 ></span>]</span> this puzzle.</p>
135 </main>
136
137 <!-- ga -->
138 <script>
139 (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
140 (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
141 m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
142 })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
143 ga('create', 'UA-69522494-1', 'auto');
144 ga('send', 'pageview');
145 </script>
146 <!-- /ga -->
147 </body>
148 </html>