Tweaked some parsing code
[advent-of-code-21.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 2021</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?26"/>
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 a massive company, and I can
23 only take 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, social media), I
27 built the whole thing myself, including the design, animations, prose, and all
28 of the puzzles.
29
30 The puzzles are most of the work; preparing a new calendar and a new set of
31 puzzles each year takes all of my free time for 4-5 months. 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="/2021/about">[About]</a></li><li><a href="/2021/events">[Events]</a></li><li><a href="https://teespring.com/stores/advent-of-code" target="_blank">[Shop]</a></li><li><a href="/2021/settings">[Settings]</a></li><li><a href="/2021/auth/logout">[Log Out]</a></li></ul></nav><div class="user">Neil Smith <a href="/2021/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;&nbsp;<span class="title-event-wrap">0.0.0.0:</span><a href="/2021">2021</a><span class="title-event-wrap"></span></h1><nav><ul><li><a href="/2021">[Calendar]</a></li><li><a href="/2021/support">[AoC++]</a></li><li><a href="/2021/sponsors">[Sponsors]</a></li><li><a href="/2021/leaderboard">[Leaderboard]</a></li><li><a href="/2021/stats">[Stats]</a></li></ul></nav></div></header>
91
92 <div id="sidebar">
93 <div id="sponsor"><div class="quiet">Our <a href="/2021/sponsors">sponsors</a> help make Advent of Code possible:</div><div class="sponsor"><a href="https://drw.com/" target="_blank" onclick="if(ga)ga('send','event','sponsor','sidebar',this.href);" rel="noopener">DRW</a> - Low latency fintech. First and fastest! Hiring in: Montreal, Chicago, London</div></div>
94 </div><!--/sidebar-->
95
96 <main>
97 <script>window.addEventListener('click', function(e,s,r){if(e.target.nodeName==='CODE'&&e.detail===3){s=window.getSelection();s.removeAllRanges();r=document.createRange();r.selectNodeContents(e.target);s.addRange(r);}});</script>
98 <article class="day-desc"><h2>--- Day 12: Passage Pathing ---</h2><p>With your <span title="Sublime.">submarine's subterranean subsystems subsisting suboptimally</span>, the only way you're getting out of this cave anytime soon is by finding a path yourself. Not just <em>a</em> path - the only way to know if you've found the <em>best</em> path is to find <em>all</em> of them.</p>
99 <p>Fortunately, the sensors are still mostly working, and so you build a rough map of the remaining caves (your puzzle input). For example:</p>
100 <pre><code>start-A
101 start-b
102 A-c
103 A-b
104 b-d
105 A-end
106 b-end
107 </code></pre>
108 <p>This is a list of how all of the caves are connected. You start in the cave named <code>start</code>, and your destination is the cave named <code>end</code>. An entry like <code>b-d</code> means that cave <code>b</code> is connected to cave <code>d</code> - that is, you can move between them.</p>
109 <p>So, the above cave system looks roughly like this:</p>
110 <pre><code> start
111 / \
112 c--A-----b--d
113 \ /
114 end
115 </code></pre>
116 <p>Your goal is to find the number of distinct <em>paths</em> that start at <code>start</code>, end at <code>end</code>, and don't visit small caves more than once. There are two types of caves: <em>big</em> caves (written in uppercase, like <code>A</code>) and <em>small</em> caves (written in lowercase, like <code>b</code>). It would be a waste of time to visit any small cave more than once, but big caves are large enough that it might be worth visiting them multiple times. So, all paths you find should <em>visit small caves at most once</em>, and can <em>visit big caves any number of times</em>.</p>
117 <p>Given these rules, there are <code><em>10</em></code> paths through this example cave system:</p>
118 <pre><code>start,A,b,A,c,A,end
119 start,A,b,A,end
120 start,A,b,end
121 start,A,c,A,b,A,end
122 start,A,c,A,b,end
123 start,A,c,A,end
124 start,A,end
125 start,b,A,c,A,end
126 start,b,A,end
127 start,b,end
128 </code></pre>
129 <p>(Each line in the above list corresponds to a single path; the caves visited by that path are listed in the order they are visited and separated by commas.)</p>
130 <p>Note that in this cave system, cave <code>d</code> is never visited by any path: to do so, cave <code>b</code> would need to be visited twice (once on the way to cave <code>d</code> and a second time when returning from cave <code>d</code>), and since cave <code>b</code> is small, this is not allowed.</p>
131 <p>Here is a slightly larger example:</p>
132 <pre><code>dc-end
133 HN-start
134 start-kj
135 dc-start
136 dc-HN
137 LN-dc
138 HN-end
139 kj-sa
140 kj-HN
141 kj-dc
142 </code></pre>
143 <p>The <code>19</code> paths through it are as follows:</p>
144 <pre><code>start,HN,dc,HN,end
145 start,HN,dc,HN,kj,HN,end
146 start,HN,dc,end
147 start,HN,dc,kj,HN,end
148 start,HN,end
149 start,HN,kj,HN,dc,HN,end
150 start,HN,kj,HN,dc,end
151 start,HN,kj,HN,end
152 start,HN,kj,dc,HN,end
153 start,HN,kj,dc,end
154 start,dc,HN,end
155 start,dc,HN,kj,HN,end
156 start,dc,end
157 start,dc,kj,HN,end
158 start,kj,HN,dc,HN,end
159 start,kj,HN,dc,end
160 start,kj,HN,end
161 start,kj,dc,HN,end
162 start,kj,dc,end
163 </code></pre>
164 <p>Finally, this even larger example has <code>226</code> paths through it:</p>
165 <pre><code>fs-end
166 he-DX
167 fs-he
168 start-DX
169 pj-DX
170 end-zg
171 zg-sl
172 zg-pj
173 pj-he
174 RW-he
175 fs-DX
176 pj-RW
177 zg-RW
178 start-pj
179 he-WI
180 zg-he
181 pj-fs
182 start-RW
183 </code></pre>
184 <p><em>How many paths through this cave system are there that visit small caves at most once?</em></p>
185 </article>
186 <p>Your puzzle answer was <code>4495</code>.</p><article class="day-desc"><h2 id="part2">--- Part Two ---</h2><p>After reviewing the available paths, you realize you might have time to visit a single small cave <em>twice</em>. Specifically, big caves can be visited any number of times, a single small cave can be visited at most twice, and the remaining small caves can be visited at most once. However, the caves named <code>start</code> and <code>end</code> can only be visited <em>exactly once each</em>: once you leave the <code>start</code> cave, you may not return to it, and once you reach the <code>end</code> cave, the path must end immediately.</p>
187 <p>Now, the <code>36</code> possible paths through the first example above are:</p>
188 <pre><code>start,A,b,A,b,A,c,A,end
189 start,A,b,A,b,A,end
190 start,A,b,A,b,end
191 start,A,b,A,c,A,b,A,end
192 start,A,b,A,c,A,b,end
193 start,A,b,A,c,A,c,A,end
194 start,A,b,A,c,A,end
195 start,A,b,A,end
196 start,A,b,d,b,A,c,A,end
197 start,A,b,d,b,A,end
198 start,A,b,d,b,end
199 start,A,b,end
200 start,A,c,A,b,A,b,A,end
201 start,A,c,A,b,A,b,end
202 start,A,c,A,b,A,c,A,end
203 start,A,c,A,b,A,end
204 start,A,c,A,b,d,b,A,end
205 start,A,c,A,b,d,b,end
206 start,A,c,A,b,end
207 start,A,c,A,c,A,b,A,end
208 start,A,c,A,c,A,b,end
209 start,A,c,A,c,A,end
210 start,A,c,A,end
211 start,A,end
212 start,b,A,b,A,c,A,end
213 start,b,A,b,A,end
214 start,b,A,b,end
215 start,b,A,c,A,b,A,end
216 start,b,A,c,A,b,end
217 start,b,A,c,A,c,A,end
218 start,b,A,c,A,end
219 start,b,A,end
220 start,b,d,b,A,c,A,end
221 start,b,d,b,A,end
222 start,b,d,b,end
223 start,b,end
224 </code></pre>
225 <p>The slightly larger example above now has <code>103</code> paths through it, and the even larger example now has <code>3509</code> paths through it.</p>
226 <p>Given these new rules, <em>how many paths through this cave system are there?</em></p>
227 </article>
228 <p>Your puzzle answer was <code>131254</code>.</p><p class="day-success">Both parts of this puzzle are complete! They provide two gold stars: **</p>
229 <p>At this point, you should <a href="/2021">return to your Advent calendar</a> and try another puzzle.</p>
230 <p>If you still want to see it, you can <a href="12/input" target="_blank">get your puzzle input</a>.</p>
231 <p>You can also <span class="share">[Share<span class="share-content">on
232 <a href="https://twitter.com/intent/tweet?text=I%27ve+completed+%22Passage+Pathing%22+%2D+Day+12+%2D+Advent+of+Code+2021&amp;url=https%3A%2F%2Fadventofcode%2Ecom%2F2021%2Fday%2F12&amp;related=ericwastl&amp;hashtags=AdventOfCode" target="_blank">Twitter</a>
233 <a href="javascript:void(0);" onclick="var mastodon_instance=prompt('Mastodon Instance / Server Name?'); if(typeof mastodon_instance==='string' && mastodon_instance.length){this.href='https://'+mastodon_instance+'/share?text=I%27ve+completed+%22Passage+Pathing%22+%2D+Day+12+%2D+Advent+of+Code+2021+%23AdventOfCode+https%3A%2F%2Fadventofcode%2Ecom%2F2021%2Fday%2F12'}else{return false;}" target="_blank">Mastodon</a
234 ></span>]</span> this puzzle.</p>
235 </main>
236
237 <!-- ga -->
238 <script>
239 (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
240 (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
241 m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
242 })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
243 ga('create', 'UA-69522494-1', 'auto');
244 ga('set', 'anonymizeIp', true);
245 ga('send', 'pageview');
246 </script>
247 <!-- /ga -->
248 </body>
249 </html>