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"/>
16 Oh, hello! Funny seeing you here.
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.
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.
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
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!
35 If you'd like to hang out, I'm @ericwastl on Twitter.
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"> <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>
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>
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>
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>
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
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>
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
147 start,HN,dc,kj,HN,end
149 start,HN,kj,HN,dc,HN,end
150 start,HN,kj,HN,dc,end
152 start,HN,kj,dc,HN,end
155 start,dc,HN,kj,HN,end
158 start,kj,HN,dc,HN,end
164 <p>Finally, this even larger example has
<code>226</code> paths through it:
</p>
184 <p><em>How many paths through this cave system are there that visit small caves at most once?
</em></p>
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
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
196 start,A,b,d,b,A,c,A,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
204 start,A,c,A,b,d,b,A,end
205 start,A,c,A,b,d,b,end
207 start,A,c,A,c,A,b,A,end
208 start,A,c,A,c,A,b,end
212 start,b,A,b,A,c,A,end
215 start,b,A,c,A,b,A,end
217 start,b,A,c,A,c,A,end
220 start,b,d,b,A,c,A,end
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>
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&url=https%3A%2F%2Fadventofcode%2Ecom%2F2021%2Fday%2F12&related=ericwastl&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>
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');