|
| 1 | +# Answers |
| 2 | + |
| 3 | +| Part 1 | Part 2 | |
| 4 | +|--------|--------| |
| 5 | +| `2946` | `1222` | |
| 6 | + |
| 7 | +## --- Day 18: Many-Worlds Interpretation --- |
| 8 | + |
| 9 | +As you approach Neptune, a planetary security system detects you and activates a giant [tractor beam](https://en.wikipedia.org/wiki/Tractor_beam) on [Triton](https://en.wikipedia.org/wiki/Triton_(moon))! You have no choice but to land. |
| 10 | + |
| 11 | +A scan of the local area reveals only one interesting feature: a massive underground vault. You generate a map of the tunnels (your puzzle input). The tunnels are too narrow to move diagonally. |
| 12 | + |
| 13 | +Only one _entrance_ (marked `@`) is present among the _open passages_ (marked `.`) and _stone walls_ (`#`), but you also detect an assortment of _keys_ (shown as lowercase letters) and _doors_ (shown as uppercase letters). Keys of a given letter open the door of the same letter: `a` opens `A`, `b` opens `B`, and so on. You aren't sure which key you need to disable the tractor beam, so you'll need to _collect all of them_. |
| 14 | + |
| 15 | +For example, suppose you have the following map: |
| 16 | + |
| 17 | + ######### |
| 18 | + #b.A.@.a# |
| 19 | + ######### |
| 20 | + |
| 21 | + |
| 22 | +Starting from the entrance (`@`), you can only access a large door (`A`) and a key (`a`). Moving toward the door doesn't help you, but you can move `2` steps to collect the key, unlocking `A` in the process: |
| 23 | + |
| 24 | + ######### |
| 25 | + #b.....@# |
| 26 | + ######### |
| 27 | + |
| 28 | + |
| 29 | +Then, you can move `6` steps to collect the only other key, `b`: |
| 30 | + |
| 31 | + ######### |
| 32 | + #@......# |
| 33 | + ######### |
| 34 | + |
| 35 | + |
| 36 | +So, collecting every key took a total of _`8`_ steps. |
| 37 | + |
| 38 | +Here is a larger example: |
| 39 | + |
| 40 | + ######################## |
| 41 | + #f.D.E.e.C.b.A.@.a.B.c.# |
| 42 | + ######################.# |
| 43 | + #d.....................# |
| 44 | + ######################## |
| 45 | + |
| 46 | + |
| 47 | +The only reasonable move is to take key `a` and unlock door `A`: |
| 48 | + |
| 49 | + ######################## |
| 50 | + #f.D.E.e.C.b.....@.B.c.# |
| 51 | + ######################.# |
| 52 | + #d.....................# |
| 53 | + ######################## |
| 54 | + |
| 55 | + |
| 56 | +Then, do the same with key `b`: |
| 57 | + |
| 58 | + ######################## |
| 59 | + #f.D.E.e.C.@.........c.# |
| 60 | + ######################.# |
| 61 | + #d.....................# |
| 62 | + ######################## |
| 63 | + |
| 64 | + |
| 65 | +...and the same with key `c`: |
| 66 | + |
| 67 | + ######################## |
| 68 | + #f.D.E.e.............@.# |
| 69 | + ######################.# |
| 70 | + #d.....................# |
| 71 | + ######################## |
| 72 | + |
| 73 | + |
| 74 | +Now, you have a choice between keys `d` and `e`. While key `e` is closer, collecting it now would be slower in the long run than collecting key `d` first, so that's the best choice: |
| 75 | + |
| 76 | + ######################## |
| 77 | + #f...E.e...............# |
| 78 | + ######################.# |
| 79 | + #@.....................# |
| 80 | + ######################## |
| 81 | + |
| 82 | + |
| 83 | +Finally, collect key `e` to unlock door `E`, then collect key `f`, taking a grand total of _`86`_ steps. |
| 84 | + |
| 85 | +Here are a few more examples: |
| 86 | + |
| 87 | +* ######################## |
| 88 | + #...............b.C.D.f# |
| 89 | + #.###################### |
| 90 | + #.....@.a.B.c.d.A.e.F.g# |
| 91 | + ######################## |
| 92 | + |
| 93 | + |
| 94 | + Shortest path is `132` steps: `b`, `a`, `c`, `d`, `f`, `e`, `g` |
| 95 | + |
| 96 | +* ################# |
| 97 | + #i.G..c...e..H.p# |
| 98 | + ########.######## |
| 99 | + #j.A..b...f..D.o# |
| 100 | + ########@######## |
| 101 | + #k.E..a...g..B.n# |
| 102 | + ########.######## |
| 103 | + #l.F..d...h..C.m# |
| 104 | + ################# |
| 105 | + |
| 106 | + |
| 107 | + Shortest paths are `136` steps; |
| 108 | + one is: `a`, `f`, `b`, `j`, `g`, `n`, `h`, `d`, `l`, `o`, `e`, `p`, `c`, `i`, `k`, `m` |
| 109 | + |
| 110 | +* ######################## |
| 111 | + #@..............ac.GI.b# |
| 112 | + ###d#e#f################ |
| 113 | + ###A#B#C################ |
| 114 | + ###g#h#i################ |
| 115 | + ######################## |
| 116 | + |
| 117 | + |
| 118 | + Shortest paths are `81` steps; one is: `a`, `c`, `f`, `i`, `d`, `g`, `b`, `e`, `h` |
| 119 | + |
| 120 | + |
| 121 | +_How many steps is the shortest path that collects all of the keys?_ |
| 122 | + |
| 123 | +----------------- |
| 124 | + |
| 125 | +## --- Part Two --- |
| 126 | + |
| 127 | +You arrive at the vault only to discover that there is not one vault, but _four_ - each with its own entrance. |
| 128 | + |
| 129 | +On your map, find the area in the middle that looks like this: |
| 130 | + |
| 131 | + ... |
| 132 | + .@. |
| 133 | + ... |
| 134 | + |
| 135 | + |
| 136 | +Update your map to instead use the correct data: |
| 137 | + |
| 138 | + @#@ |
| 139 | + ### |
| 140 | + @#@ |
| 141 | + |
| 142 | + |
| 143 | +This change will split your map into four separate sections, each with its own entrance: |
| 144 | + |
| 145 | +<pre><code>####### ####### |
| 146 | +#a.#Cd# #a.#Cd# |
| 147 | +##...## ##<b>@#@</b>## |
| 148 | +##.@.## --> ##<b>###</b>## |
| 149 | +##...## ##<b>@#@</b>## |
| 150 | +#cB#Ab# #cB#Ab# |
| 151 | +####### ####### |
| 152 | +</code></pre> |
| 153 | + |
| 154 | +Because some of the keys are for doors in other vaults, it would take much too long to collect all of the keys by yourself. Instead, you deploy four remote-controlled robots. Each starts at one of the entrances (`@`). |
| 155 | + |
| 156 | +Your goal is still to _collect all of the keys in the fewest steps_, but now, each robot has its own position and can move independently. You can only remotely control a single robot at a time. Collecting a key instantly unlocks any corresponding doors, regardless of the vault in which the key or door is found. |
| 157 | + |
| 158 | +For example, in the map above, the top-left robot first collects key `a`, unlocking door `A` in the bottom-right vault: |
| 159 | + |
| 160 | + ####### |
| 161 | + #@.#Cd# |
| 162 | + ##.#@## |
| 163 | + ####### |
| 164 | + ##@#@## |
| 165 | + #cB#.b# |
| 166 | + ####### |
| 167 | + |
| 168 | + |
| 169 | +Then, the bottom-right robot collects key `b`, unlocking door `B` in the bottom-left vault: |
| 170 | + |
| 171 | + ####### |
| 172 | + #@.#Cd# |
| 173 | + ##.#@## |
| 174 | + ####### |
| 175 | + ##@#.## |
| 176 | + #c.#.@# |
| 177 | + ####### |
| 178 | + |
| 179 | + |
| 180 | +Then, the bottom-left robot collects key `c`: |
| 181 | + |
| 182 | + ####### |
| 183 | + #@.#.d# |
| 184 | + ##.#@## |
| 185 | + ####### |
| 186 | + ##.#.## |
| 187 | + #@.#.@# |
| 188 | + ####### |
| 189 | + |
| 190 | + |
| 191 | +Finally, the top-right robot collects key `d`: |
| 192 | + |
| 193 | + ####### |
| 194 | + #@.#.@# |
| 195 | + ##.#.## |
| 196 | + ####### |
| 197 | + ##.#.## |
| 198 | + #@.#.@# |
| 199 | + ####### |
| 200 | + |
| 201 | + |
| 202 | +In this example, it only took _`8`_ steps to collect all of the keys. |
| 203 | + |
| 204 | +Sometimes, multiple robots might have keys available, or a robot might have to wait for multiple keys to be collected: |
| 205 | + |
| 206 | + ############### |
| 207 | + #d.ABC.#.....a# |
| 208 | + ######@#@###### |
| 209 | + ############### |
| 210 | + ######@#@###### |
| 211 | + #b.....#.....c# |
| 212 | + ############### |
| 213 | + |
| 214 | + |
| 215 | +First, the top-right, bottom-left, and bottom-right robots take turns collecting keys `a`, `b`, and `c`, a total of `6 + 6 + 6 = 18` steps. Then, the top-left robot can access key `d`, spending another `6` steps; collecting all of the keys here takes a minimum of _`24`_ steps. |
| 216 | + |
| 217 | +Here's a more complex example: |
| 218 | + |
| 219 | + ############# |
| 220 | + #DcBa.#.GhKl# |
| 221 | + #.###@#@#I### |
| 222 | + #e#d#####j#k# |
| 223 | + ###C#@#@###J# |
| 224 | + #fEbA.#.FgHi# |
| 225 | + ############# |
| 226 | + |
| 227 | + |
| 228 | +* Top-left robot collects key `a`. |
| 229 | +* Bottom-left robot collects key `b`. |
| 230 | +* Top-left robot collects key `c`. |
| 231 | +* Bottom-left robot collects key `d`. |
| 232 | +* Top-left robot collects key `e`. |
| 233 | +* Bottom-left robot collects key `f`. |
| 234 | +* Bottom-right robot collects key `g`. |
| 235 | +* Top-right robot collects key `h`. |
| 236 | +* Bottom-right robot collects key `i`. |
| 237 | +* Top-right robot collects key `j`. |
| 238 | +* Bottom-right robot collects key `k`. |
| 239 | +* Top-right robot collects key `l`. |
| 240 | + |
| 241 | +In the above example, the fewest steps to collect all of the keys is _`32`_. |
| 242 | + |
| 243 | +Here's an example with more choices: |
| 244 | + |
| 245 | + ############# |
| 246 | + #g#f.D#..h#l# |
| 247 | + #F###e#E###.# |
| 248 | + #dCba@#@BcIJ# |
| 249 | + ############# |
| 250 | + #nK.L@#@G...# |
| 251 | + #M###N#H###.# |
| 252 | + #o#m..#i#jk.# |
| 253 | + ############# |
| 254 | + |
| 255 | + |
| 256 | +One solution with the fewest steps is: |
| 257 | + |
| 258 | +* Top-left robot collects key `e`. |
| 259 | +* Top-right robot collects key `h`. |
| 260 | +* Bottom-right robot collects key `i`. |
| 261 | +* Top-left robot collects key `a`. |
| 262 | +* Top-left robot collects key `b`. |
| 263 | +* Top-right robot collects key `c`. |
| 264 | +* Top-left robot collects key `d`. |
| 265 | +* Top-left robot collects key `f`. |
| 266 | +* Top-left robot collects key `g`. |
| 267 | +* Bottom-right robot collects key `k`. |
| 268 | +* Bottom-right robot collects key `j`. |
| 269 | +* Top-right robot collects key `l`. |
| 270 | +* Bottom-left robot collects key `n`. |
| 271 | +* Bottom-left robot collects key `m`. |
| 272 | +* Bottom-left robot collects key `o`. |
| 273 | + |
| 274 | +This example requires at least _`72`_ steps to collect all keys. |
| 275 | + |
| 276 | +After updating your map and using the remote-controlled robots, _what is the fewest steps necessary to collect all of the keys?_ |
0 commit comments