Day 12
[advent-of-code-2021.git] / day12 / task.txt
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.
3
4 Fortunately, the sensors are still mostly working, and so you build a rough map of the remaining caves (your puzzle input). For example:
5
6 start-A
7 start-b
8 A-c
9 A-b
10 b-d
11 A-end
12 b-end
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.
14
15 So, the above cave system looks roughly like this:
16
17     start
18     /   \
19 c--A-----b--d
20     \   /
21      end
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.
23
24 Given these rules, there are 10 paths through this example cave system:
25
26 start,A,b,A,c,A,end
27 start,A,b,A,end
28 start,A,b,end
29 start,A,c,A,b,A,end
30 start,A,c,A,b,end
31 start,A,c,A,end
32 start,A,end
33 start,b,A,c,A,end
34 start,b,A,end
35 start,b,end
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.)
37
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.
39
40 Here is a slightly larger example:
41
42 dc-end
43 HN-start
44 start-kj
45 dc-start
46 dc-HN
47 LN-dc
48 HN-end
49 kj-sa
50 kj-HN
51 kj-dc
52 The 19 paths through it are as follows:
53
54 start,HN,dc,HN,end
55 start,HN,dc,HN,kj,HN,end
56 start,HN,dc,end
57 start,HN,dc,kj,HN,end
58 start,HN,end
59 start,HN,kj,HN,dc,HN,end
60 start,HN,kj,HN,dc,end
61 start,HN,kj,HN,end
62 start,HN,kj,dc,HN,end
63 start,HN,kj,dc,end
64 start,dc,HN,end
65 start,dc,HN,kj,HN,end
66 start,dc,end
67 start,dc,kj,HN,end
68 start,kj,HN,dc,HN,end
69 start,kj,HN,dc,end
70 start,kj,HN,end
71 start,kj,dc,HN,end
72 start,kj,dc,end
73 Finally, this even larger example has 226 paths through it:
74
75 fs-end
76 he-DX
77 fs-he
78 start-DX
79 pj-DX
80 end-zg
81 zg-sl
82 zg-pj
83 pj-he
84 RW-he
85 fs-DX
86 pj-RW
87 zg-RW
88 start-pj
89 he-WI
90 zg-he
91 pj-fs
92 start-RW
93 How many paths through this cave system are there that visit small caves at most once?
94
95 Your puzzle answer was 3761.
96
97 --- Part Two ---
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.
99
100 Now, the 36 possible paths through the first example above are:
101
102 start,A,b,A,b,A,c,A,end
103 start,A,b,A,b,A,end
104 start,A,b,A,b,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
108 start,A,b,A,c,A,end
109 start,A,b,A,end
110 start,A,b,d,b,A,c,A,end
111 start,A,b,d,b,A,end
112 start,A,b,d,b,end
113 start,A,b,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
117 start,A,c,A,b,A,end
118 start,A,c,A,b,d,b,A,end
119 start,A,c,A,b,d,b,end
120 start,A,c,A,b,end
121 start,A,c,A,c,A,b,A,end
122 start,A,c,A,c,A,b,end
123 start,A,c,A,c,A,end
124 start,A,c,A,end
125 start,A,end
126 start,b,A,b,A,c,A,end
127 start,b,A,b,A,end
128 start,b,A,b,end
129 start,b,A,c,A,b,A,end
130 start,b,A,c,A,b,end
131 start,b,A,c,A,c,A,end
132 start,b,A,c,A,end
133 start,b,A,end
134 start,b,d,b,A,c,A,end
135 start,b,d,b,A,end
136 start,b,d,b,end
137 start,b,end
138 The slightly larger example above now has 103 paths through it, and the even larger example now has 3509 paths through it.
139
140 Given these new rules, how many paths through this cave system are there?
141
142 Your puzzle answer was 99138.
143
144 Both parts of this puzzle are complete! They provide two gold stars: **
145
146 At this point, you should return to your Advent calendar and try another puzzle.
147
148 If you still want to see it, you can get your puzzle input.
149
150 You can also [Share] this puzzle.