|
| 1 | +# Day 8: Haunted Wasteland |
| 2 | + |
| 3 | +[https://adventofcode.com/2023/day/8](https://adventofcode.com/2023/day/8) |
| 4 | + |
| 5 | +## Description |
| 6 | + |
| 7 | +### Part One |
| 8 | + |
| 9 | +You're still riding a camel across Desert Island when you spot a sandstorm quickly approaching. When you turn to warn the Elf, she disappears before your eyes! To be fair, she had just finished warning you about _ghosts_ a few minutes ago. |
| 10 | + |
| 11 | +One of the camel's pouches is labeled "maps" - sure enough, it's full of documents (your puzzle input) about how to navigate the desert. At least, you're pretty sure that's what they are; one of the documents contains a list of left/right instructions, and the rest of the documents seem to describe some kind of _network_ of labeled nodes. |
| 12 | + |
| 13 | +It seems like you're meant to use the _left/right_ instructions to _navigate the network_. Perhaps if you have the camel follow the same instructions, you can escape the haunted wasteland! |
| 14 | + |
| 15 | +After examining the maps for a bit, two nodes stick out: `AAA` and `ZZZ`. You feel like `AAA` is where you are now, and you have to follow the left/right instructions until you reach `ZZZ`. |
| 16 | + |
| 17 | +This format defines each _node_ of the network individually. For example: |
| 18 | + |
| 19 | + RL |
| 20 | + |
| 21 | + AAA = (BBB, CCC) |
| 22 | + BBB = (DDD, EEE) |
| 23 | + CCC = (ZZZ, GGG) |
| 24 | + DDD = (DDD, DDD) |
| 25 | + EEE = (EEE, EEE) |
| 26 | + GGG = (GGG, GGG) |
| 27 | + ZZZ = (ZZZ, ZZZ) |
| 28 | + |
| 29 | + |
| 30 | +Starting with `AAA`, you need to _look up the next element_ based on the next left/right instruction in your input. In this example, start with `AAA` and go _right_ (`R`) by choosing the right element of `AAA`, _`CCC`_. Then, `L` means to choose the _left_ element of `CCC`, _`ZZZ`_. By following the left/right instructions, you reach `ZZZ` in _`2`_ steps. |
| 31 | + |
| 32 | +Of course, you might not find `ZZZ` right away. If you run out of left/right instructions, repeat the whole sequence of instructions as necessary: `RL` really means `RLRLRLRLRLRLRLRL...` and so on. For example, here is a situation that takes _`6`_ steps to reach `ZZZ`: |
| 33 | + |
| 34 | + LLR |
| 35 | + |
| 36 | + AAA = (BBB, BBB) |
| 37 | + BBB = (AAA, ZZZ) |
| 38 | + ZZZ = (ZZZ, ZZZ) |
| 39 | + |
| 40 | + |
| 41 | +Starting at `AAA`, follow the left/right instructions. _How many steps are required to reach `ZZZ`?_ |
| 42 | + |
| 43 | +### Part Two |
| 44 | + |
| 45 | +The <span title="Duhduhduhduhduh! Dah, duhduhduhduhduh!">sandstorm</span> is upon you and you aren't any closer to escaping the wasteland. You had the camel follow the instructions, but you've barely left your starting position. It's going to take _significantly more steps_ to escape! |
| 46 | + |
| 47 | +What if the map isn't for people - what if the map is for _ghosts_? Are ghosts even bound by the laws of spacetime? Only one way to find out. |
| 48 | + |
| 49 | +After examining the maps a bit longer, your attention is drawn to a curious fact: the number of nodes with names ending in `A` is equal to the number ending in `Z`! If you were a ghost, you'd probably just _start at every node that ends with `A`_ and follow all of the paths at the same time until they all simultaneously end up at nodes that end with `Z`. |
| 50 | + |
| 51 | +For example: |
| 52 | + |
| 53 | + LR |
| 54 | + |
| 55 | + 11A = (11B, XXX) |
| 56 | + 11B = (XXX, 11Z) |
| 57 | + 11Z = (11B, XXX) |
| 58 | + 22A = (22B, XXX) |
| 59 | + 22B = (22C, 22C) |
| 60 | + 22C = (22Z, 22Z) |
| 61 | + 22Z = (22B, 22B) |
| 62 | + XXX = (XXX, XXX) |
| 63 | + |
| 64 | + |
| 65 | +Here, there are two starting nodes, `11A` and `22A` (because they both end with `A`). As you follow each left/right instruction, use that instruction to _simultaneously_ navigate away from both nodes you're currently on. Repeat this process until _all_ of the nodes you're currently on end with `Z`. (If only some of the nodes you're on end with `Z`, they act like any other node and you continue as normal.) In this example, you would proceed as follows: |
| 66 | + |
| 67 | +* Step 0: You are at `11A` and `22A`. |
| 68 | +* Step 1: You choose all of the _left_ paths, leading you to `11B` and `22B`. |
| 69 | +* Step 2: You choose all of the _right_ paths, leading you to _`11Z`_ and `22C`. |
| 70 | +* Step 3: You choose all of the _left_ paths, leading you to `11B` and _`22Z`_. |
| 71 | +* Step 4: You choose all of the _right_ paths, leading you to _`11Z`_ and `22B`. |
| 72 | +* Step 5: You choose all of the _left_ paths, leading you to `11B` and `22C`. |
| 73 | +* Step 6: You choose all of the _right_ paths, leading you to _`11Z`_ and _`22Z`_. |
| 74 | + |
| 75 | +So, in this example, you end up entirely on nodes that end in `Z` after _`6`_ steps. |
| 76 | + |
| 77 | +Simultaneously start on every node that ends with `A`. _How many steps does it take before you're only on nodes that end with `Z`?_ |
0 commit comments