1 --- Day 12: Passage Pathing ---
2 With your submarine's subterranean subsystems subsisting suboptimally, the only way you're getting out of this cave anytime soon is by finding a path yourself. Not just a path - the only way to know if you've found the best path is to find all of them.
4 Fortunately, the sensors are still mostly working, and so you build a rough map of the remaining caves (your puzzle input). For example:
13 This is a list of how all of the caves are connected. You start in the cave named start, and your destination is the cave named end. An entry like b-d means that cave b is connected to cave d - that is, you can move between them.
15 So, the above cave system looks roughly like this:
22 Your goal is to find the number of distinct paths that start at start, end at end, and don't visit small caves more than once. There are two types of caves: big caves (written in uppercase, like A) and small caves (written in lowercase, like b). 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 visit small caves at most once, and can visit big caves any number of times.
24 Given these rules, there are 10 paths through this example cave system:
36 (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.)
38 Note that in this cave system, cave d is never visited by any path: to do so, cave b would need to be visited twice (once on the way to cave d and a second time when returning from cave d), and since cave b is small, this is not allowed.
40 Here is a slightly larger example:
52 The 19 paths through it are as follows:
55 start,HN,dc,HN,kj,HN,end
59 start,HN,kj,HN,dc,HN,end
73 Finally, this even larger example has 226 paths through it:
93 How many paths through this cave system are there that visit small caves at most once?
95 Your puzzle answer was 3761.
98 After reviewing the available paths, you realize you might have time to visit a single small cave twice. 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 start and end can only be visited exactly once each: once you leave the start cave, you may not return to it, and once you reach the end cave, the path must end immediately.
100 Now, the 36 possible paths through the first example above are:
102 start,A,b,A,b,A,c,A,end
105 start,A,b,A,c,A,b,A,end
106 start,A,b,A,c,A,b,end
107 start,A,b,A,c,A,c,A,end
110 start,A,b,d,b,A,c,A,end
114 start,A,c,A,b,A,b,A,end
115 start,A,c,A,b,A,b,end
116 start,A,c,A,b,A,c,A,end
118 start,A,c,A,b,d,b,A,end
119 start,A,c,A,b,d,b,end
121 start,A,c,A,c,A,b,A,end
122 start,A,c,A,c,A,b,end
126 start,b,A,b,A,c,A,end
129 start,b,A,c,A,b,A,end
131 start,b,A,c,A,c,A,end
134 start,b,d,b,A,c,A,end
138 The slightly larger example above now has 103 paths through it, and the even larger example now has 3509 paths through it.
140 Given these new rules, how many paths through this cave system are there?
142 Your puzzle answer was 99138.
144 Both parts of this puzzle are complete! They provide two gold stars: **
146 At this point, you should return to your Advent calendar and try another puzzle.
148 If you still want to see it, you can get your puzzle input.
150 You can also [Share] this puzzle.