|
| 1 | +# Day 11: Cosmic Expansion --- |
| 2 | +You continue following signs for "Hot Springs" and eventually come across an |
| 3 | +[observatory](https://en.wikipedia.org/wiki/Observatory). The Elf within turns out to be a researcher studying cosmic |
| 4 | +expansion using the giant telescope here. |
| 5 | + |
| 6 | +He doesn't know anything about the missing machine parts; he's only visiting for this research project. However, he |
| 7 | +confirms that the hot springs are the next-closest area likely to have people; he'll even take you straight there once |
| 8 | +he's done with today's observation analysis. |
| 9 | + |
| 10 | +Maybe you can help him with the analysis to speed things up? |
| 11 | + |
| 12 | +The researcher has collected a bunch of data and compiled the data into a single giant **image** (your puzzle input). |
| 13 | +The image includes **empty space** (`.`) and **galaxies** (`#`). For example: |
| 14 | +``` |
| 15 | +...#...... |
| 16 | +.......#.. |
| 17 | +#......... |
| 18 | +.......... |
| 19 | +......#... |
| 20 | +.#........ |
| 21 | +.........# |
| 22 | +.......... |
| 23 | +.......#.. |
| 24 | +#...#..... |
| 25 | +``` |
| 26 | +The researcher is trying to figure out the sum of the lengths of the **shortest path between every pair of galaxies**. |
| 27 | +However, there's a catch: the universe expanded in the time it took the light from those galaxies to reach the |
| 28 | +observatory. |
| 29 | + |
| 30 | +Due to something involving gravitational effects, **only some space expands**. In fact, the result is that **any rows |
| 31 | +or columns that contain no galaxies** should all actually be twice as big. |
| 32 | + |
| 33 | +In the above example, three columns and two rows contain no galaxies: |
| 34 | +``` |
| 35 | + v v v |
| 36 | + ...#...... |
| 37 | + .......#.. |
| 38 | + #......... |
| 39 | +>..........< |
| 40 | + ......#... |
| 41 | + .#........ |
| 42 | + .........# |
| 43 | +>..........< |
| 44 | + .......#.. |
| 45 | + #...#..... |
| 46 | + ^ ^ ^ |
| 47 | +``` |
| 48 | +These rows and columns need to be **twice as big**; the result of cosmic expansion therefore looks like this: |
| 49 | +``` |
| 50 | +....#........ |
| 51 | +.........#... |
| 52 | +#............ |
| 53 | +............. |
| 54 | +............. |
| 55 | +........#.... |
| 56 | +.#........... |
| 57 | +............# |
| 58 | +............. |
| 59 | +............. |
| 60 | +.........#... |
| 61 | +#....#....... |
| 62 | +``` |
| 63 | +Equipped with this expanded universe, the shortest path between every pair of galaxies can be found. It can help to |
| 64 | +assign every galaxy a unique number: |
| 65 | +``` |
| 66 | +....1........ |
| 67 | +.........2... |
| 68 | +3............ |
| 69 | +............. |
| 70 | +............. |
| 71 | +........4.... |
| 72 | +.5........... |
| 73 | +............6 |
| 74 | +............. |
| 75 | +............. |
| 76 | +.........7... |
| 77 | +8....9....... |
| 78 | +``` |
| 79 | +In these 9 galaxies, there are **36 pairs**. Only count each pair once; order within the pair doesn't matter. For each |
| 80 | +pair, find any shortest path between the two galaxies using only steps that move up, down, left, or right exactly one |
| 81 | +`.` or `#` at a time. (The shortest path between two galaxies is allowed to pass through another galaxy.) |
| 82 | + |
| 83 | +For example, here is one of the shortest paths between galaxies `5` and `9`: |
| 84 | +``` |
| 85 | +....1........ |
| 86 | +.........2... |
| 87 | +3............ |
| 88 | +............. |
| 89 | +............. |
| 90 | +........4.... |
| 91 | +.5........... |
| 92 | +.##.........6 |
| 93 | +..##......... |
| 94 | +...##........ |
| 95 | +....##...7... |
| 96 | +8....9....... |
| 97 | +``` |
| 98 | +This path has length **`9`** because it takes a minimum of **nine steps** to get from galaxy `5` to galaxy `9` (the |
| 99 | +eight locations marked `#` plus the step onto galaxy `9` itself). Here are some other example shortest path lengths: |
| 100 | +* Between galaxy `1` and galaxy `7`: `15` |
| 101 | +* Between galaxy `3` and galaxy `6`: `17` |
| 102 | +* Between galaxy `8` and galaxy `9`: `5` |
| 103 | + |
| 104 | +In this example, after expanding the universe, the sum of the shortest path between all 36 pairs of galaxies is |
| 105 | +**`374`**. |
| 106 | + |
| 107 | +Expand the universe, then find the length of the shortest path between every pair of galaxies. **What is the sum of |
| 108 | +these lengths**? |
0 commit comments