|
| 1 | +# Day 10: Pipe Maze |
| 2 | +You use the hang glider to ride the hot air from Desert Island all the way up to the floating metal island. This island |
| 3 | +is surprisingly cold and there definitely aren't any thermals to glide on, so you leave your hang glider behind. |
| 4 | + |
| 5 | +You wander around for a while, but you don't find any people or animals. However, you do occasionally find signposts |
| 6 | +labeled "[Hot Springs](https://en.wikipedia.org/wiki/Hot_spring)" pointing in a seemingly consistent direction; maybe |
| 7 | +you can find someone at the hot springs and ask them where the desert-machine parts are made. |
| 8 | + |
| 9 | +The landscape here is alien; even the flowers and trees are made of metal. As you stop to admire some metal grass, |
| 10 | +you notice something metallic scurry away in your peripheral vision and jump into a big pipe! It didn't look like any |
| 11 | +animal you've ever seen; if you want a better look, you'll need to get ahead of it. |
| 12 | + |
| 13 | +Scanning the area, you discover that the entire field you're standing on is densely packed with pipes; it was hard to |
| 14 | +tell at first because they're the same metallic silver color as the "ground". You make a quick sketch of all of the |
| 15 | +surface pipes you can see (your puzzle input). |
| 16 | + |
| 17 | +The pipes are arranged in a two-dimensional grid of **tiles**: |
| 18 | +* `|` is a **vertical pipe** connecting `north` and `south`. |
| 19 | +* `-` is a **horizontal pipe** connecting `east` and `west`. |
| 20 | +* `L` is a **90-degree bend** connecting `north` and `east`. |
| 21 | +* `J` is a **90-degree bend** connecting `north` and `west`. |
| 22 | +* `7` is a **90-degree bend** connecting `south` and `west`. |
| 23 | +* `F` is a **90-degree bend** connecting `south` and `east`. |
| 24 | +* `.` is **ground**; there is no pipe in this tile. |
| 25 | +* `S` is the **starting position** of the animal; there is a pipe on this tile, but your sketch doesn't show what shape |
| 26 | +the pipe has. |
| 27 | + |
| 28 | +Based on the acoustics of the animal's scurrying, you're confident the pipe that contains the animal is **one large, |
| 29 | +continuous loop**. |
| 30 | + |
| 31 | +For example, here is a square loop of pipe: |
| 32 | +``` |
| 33 | +..... |
| 34 | +.F-7. |
| 35 | +.|.|. |
| 36 | +.L-J. |
| 37 | +..... |
| 38 | +``` |
| 39 | +If the animal had entered this loop in the northwest corner, the sketch would instead look like this: |
| 40 | +``` |
| 41 | +..... |
| 42 | +.S-7. |
| 43 | +.|.|. |
| 44 | +.L-J. |
| 45 | +..... |
| 46 | +``` |
| 47 | +In the above diagram, the `S` tile is still a 90-degree `F` bend: you can tell because of how the adjacent pipes |
| 48 | +connect to it. |
| 49 | + |
| 50 | +Unfortunately, there are also many pipes that **aren't connected to the loop**! This sketch shows the same loop as |
| 51 | +above: |
| 52 | +``` |
| 53 | +-L|F7 |
| 54 | +7S-7| |
| 55 | +L|7|| |
| 56 | +-L-J| |
| 57 | +L|-JF |
| 58 | +``` |
| 59 | +In the above diagram, you can still figure out which pipes form the main loop: they're the ones connected to `S`, pipes |
| 60 | +those pipes connect to, pipes **those** pipes connect to, and so on. Every pipe in the main loop connects to its two |
| 61 | +neighbors (including `S`, which will have exactly two pipes connecting to it, and which is assumed to connect back to |
| 62 | +those two pipes). |
| 63 | + |
| 64 | +Here is a sketch that contains a slightly more complex main loop: |
| 65 | +``` |
| 66 | +..F7. |
| 67 | +.FJ|. |
| 68 | +SJ.L7 |
| 69 | +|F--J |
| 70 | +LJ... |
| 71 | +``` |
| 72 | +Here's the same example sketch with the extra, non-main-loop pipe tiles also shown: |
| 73 | +``` |
| 74 | +7-F7- |
| 75 | +.FJ|7 |
| 76 | +SJLL7 |
| 77 | +|F--J |
| 78 | +LJ.LJ |
| 79 | +``` |
| 80 | +If you want to **get out ahead of the animal**, you should find the tile in the loop that is **farthest** from the |
| 81 | +starting position. Because the animal is in the pipe, it doesn't make sense to measure this by direct distance. |
| 82 | +Instead, you need to find the tile that would take the longest number of steps **along the loop** to reach from the |
| 83 | +starting point - regardless of which way around the loop the animal went. |
| 84 | + |
| 85 | +In the first example with the square loop: |
| 86 | +``` |
| 87 | +..... |
| 88 | +.S-7. |
| 89 | +.|.|. |
| 90 | +.L-J. |
| 91 | +..... |
| 92 | +``` |
| 93 | +You can count the distance each tile in the loop is from the starting point like this: |
| 94 | +``` |
| 95 | +..... |
| 96 | +.012. |
| 97 | +.1.3. |
| 98 | +.234. |
| 99 | +..... |
| 100 | +``` |
| 101 | +In this example, the farthest point from the start is **`4`** steps away. |
| 102 | + |
| 103 | +Here's the more complex loop again: |
| 104 | +``` |
| 105 | +..F7. |
| 106 | +.FJ|. |
| 107 | +SJ.L7 |
| 108 | +|F--J |
| 109 | +LJ... |
| 110 | +``` |
| 111 | +Here are the distances for each tile on that loop: |
| 112 | +``` |
| 113 | +..45. |
| 114 | +.236. |
| 115 | +01.78 |
| 116 | +14567 |
| 117 | +23... |
| 118 | +``` |
| 119 | +Find the single giant loop starting at `S`. **How many steps along the loop does it take to get from the starting |
| 120 | +position to the point farthest from the starting position**? |
0 commit comments