90 lines
5.2 KiB
Markdown
90 lines
5.2 KiB
Markdown
|
|
<article class="day-desc"><h2>--- Day 11: Cosmic Expansion ---</h2><p>You continue following signs for "Hot Springs" and eventually come across an <a href="https://en.wikipedia.org/wiki/Observatory" target="_blank">observatory</a>. The Elf within turns out to be a researcher studying cosmic expansion using the giant telescope here.</p>
|
|
<p>He doesn't know anything about the missing machine parts; he's only visiting for this research project. However, he confirms that the hot springs are the next-closest area likely to have people; he'll even take you straight there once he's done with today's observation analysis.</p>
|
|
<p>Maybe you can help him with the analysis to speed things up?</p>
|
|
<p>The researcher has collected a bunch of data and compiled the data into a single giant <em>image</em> (your puzzle input). The image includes <em>empty space</em> (<code>.</code>) and <em>galaxies</em> (<code>#</code>). For example:</p>
|
|
<pre><code>...#......
|
|
.......#..
|
|
#.........
|
|
..........
|
|
......#...
|
|
.#........
|
|
.........#
|
|
..........
|
|
.......#..
|
|
#...#.....
|
|
</code></pre>
|
|
<p>The researcher is trying to figure out the sum of the lengths of the <em>shortest path between every pair of galaxies</em>. However, there's a catch: the universe expanded in the time it took the light from those galaxies to reach the observatory.</p>
|
|
<p>Due to something involving gravitational effects, <em>only some space expands</em>. In fact, the result is that <em>any rows or columns that contain no galaxies</em> should all actually be twice as big.</p>
|
|
<p>In the above example, three columns and two rows contain no galaxies:</p>
|
|
<pre><code> v v v
|
|
...#......
|
|
.......#..
|
|
#.........
|
|
>..........<
|
|
......#...
|
|
.#........
|
|
.........#
|
|
>..........<
|
|
.......#..
|
|
#...#.....
|
|
^ ^ ^
|
|
</code></pre>
|
|
<p>These rows and columns need to be <em>twice as big</em>; the result of cosmic expansion therefore looks like this:</p>
|
|
<pre><code>....#........
|
|
.........#...
|
|
#............
|
|
.............
|
|
.............
|
|
........#....
|
|
.#...........
|
|
............#
|
|
.............
|
|
.............
|
|
.........#...
|
|
#....#.......
|
|
</code></pre>
|
|
<p>Equipped with this expanded universe, the shortest path between every pair of galaxies can be found. It can help to assign every galaxy a unique number:</p>
|
|
<pre><code>....1........
|
|
.........2...
|
|
3............
|
|
.............
|
|
.............
|
|
........4....
|
|
.5...........
|
|
............6
|
|
.............
|
|
.............
|
|
.........7...
|
|
8....9.......
|
|
</code></pre>
|
|
<p>In these 9 galaxies, there are <em>36 pairs</em>. Only count each pair once; order within the pair doesn't matter. For each pair, find any shortest path between the two galaxies using only steps that move up, down, left, or right exactly one <code>.</code> or <code>#</code> at a time. (The shortest path between two galaxies is allowed to pass through another galaxy.)</p>
|
|
<p>For example, here is one of the shortest paths between galaxies <code>5</code> and <code>9</code>:</p>
|
|
<pre><code>....1........
|
|
.........2...
|
|
3............
|
|
.............
|
|
.............
|
|
........4....
|
|
.5...........
|
|
.##.........6
|
|
..##.........
|
|
...##........
|
|
....##...7...
|
|
8....9.......
|
|
</code></pre>
|
|
<p>This path has length <code><em>9</em></code> because it takes a minimum of <em>nine steps</em> to get from galaxy <code>5</code> to galaxy <code>9</code> (the eight locations marked <code>#</code> plus the step onto galaxy <code>9</code> itself). Here are some other example shortest path lengths:</p>
|
|
<ul>
|
|
<li>Between galaxy <code>1</code> and galaxy <code>7</code>: 15</li>
|
|
<li>Between galaxy <code>3</code> and galaxy <code>6</code>: 17</li>
|
|
<li>Between galaxy <code>8</code> and galaxy <code>9</code>: 5</li>
|
|
</ul>
|
|
<p>In this example, after expanding the universe, the sum of the shortest path between all 36 pairs of galaxies is <code><em>374</em></code>.</p>
|
|
<p>Expand the universe, then find the length of the shortest path between every pair of galaxies. <em>What is the sum of these lengths?</em></p>
|
|
|
|
<p>Your puzzle answer was <code>9724940</code>.</p><p class="day-success">The first half of this puzzle is complete! It provides one gold star: *</p>
|
|
<article class="day-desc"><h2 id="part2">--- Part Two ---</h2><p>The galaxies are much <em>older</em> (and thus much <em>farther apart</em>) than the researcher initially estimated.</p>
|
|
<p>Now, instead of the expansion you did before, make each empty row or column <em><span title="And you have to have your pinky near your mouth when you do it.">one million</span> times</em> larger. That is, each empty row should be replaced with <code>1000000</code> empty rows, and each empty column should be replaced with <code>1000000</code> empty columns.</p>
|
|
<p>(In the example above, if each empty row or column were merely <code>10</code> times larger, the sum of the shortest paths between every pair of galaxies would be <code><em>1030</em></code>. If each empty row or column were merely <code>100</code> times larger, the sum of the shortest paths between every pair of galaxies would be <code><em>8410</em></code>. However, your universe will need to expand far beyond these values.)</p>
|
|
<p>Starting with the same initial image, expand the universe according to these new rules, then find the length of the shortest path between every pair of galaxies. <em>What is the sum of these lengths?</em></p>
|