|
| 1 | +# Answers |
| 2 | + |
| 3 | +| Part 1 | Part 2 | |
| 4 | +|--------|--------| |
| 5 | +| 4233 | 45290 | |
| 6 | + |
| 7 | +## --- Day 6: Chronal Coordinates --- |
| 8 | + |
| 9 | +The device on your wrist beeps several times, and once again you feel like you're falling. |
| 10 | + |
| 11 | +"Situation critical," the device announces. "Destination indeterminate. Chronal interference detected. Please specify new target coordinates." |
| 12 | + |
| 13 | +The device then produces a list of coordinates (your puzzle input). Are they places it thinks are safe or dangerous? It recommends you check manual page 729. The Elves did not give you a manual. |
| 14 | + |
| 15 | +_If they're dangerous,_ maybe you can minimize the danger by finding the coordinate that gives the largest distance from the other points. |
| 16 | + |
| 17 | +Using only the [Manhattan distance](https://en.wikipedia.org/wiki/Taxicab_geometry), determine the _area_ around each coordinate by counting the number of [integer](https://en.wikipedia.org/wiki/Integer) X,Y locations that are _closest_ to that coordinate (and aren't _tied in distance_ to any other coordinate). |
| 18 | + |
| 19 | +Your goal is to find the size of the _largest area_ that isn't infinite. For example, consider the following list of coordinates: |
| 20 | + |
| 21 | + 1, 1 |
| 22 | + 1, 6 |
| 23 | + 8, 3 |
| 24 | + 3, 4 |
| 25 | + 5, 5 |
| 26 | + 8, 9 |
| 27 | + |
| 28 | + |
| 29 | +If we name these coordinates `A` through `F`, we can draw them on a grid, putting `0,0` at the top left: |
| 30 | + |
| 31 | + .......... |
| 32 | + .A........ |
| 33 | + .......... |
| 34 | + ........C. |
| 35 | + ...D...... |
| 36 | + .....E.... |
| 37 | + .B........ |
| 38 | + .......... |
| 39 | + .......... |
| 40 | + ........F. |
| 41 | + |
| 42 | + |
| 43 | +This view is partial - the actual grid extends infinitely in all directions. Using the Manhattan distance, each location's closest coordinate can be determined, shown here in lowercase: |
| 44 | + |
| 45 | + aaaaa.cccc |
| 46 | + aAaaa.cccc |
| 47 | + aaaddecccc |
| 48 | + aadddeccCc |
| 49 | + ..dDdeeccc |
| 50 | + bb.deEeecc |
| 51 | + bBb.eeee.. |
| 52 | + bbb.eeefff |
| 53 | + bbb.eeffff |
| 54 | + bbb.ffffFf |
| 55 | + |
| 56 | + |
| 57 | +Locations shown as `.` are equally far from two or more coordinates, and so they don't count as being closest to any. |
| 58 | + |
| 59 | +In this example, the areas of coordinates A, B, C, and F are infinite - while not shown here, their areas extend forever outside the visible grid. However, the areas of coordinates D and E are finite: D is closest to 9 locations, and E is closest to 17 (both including the coordinate's location itself). Therefore, in this example, the size of the largest area is _17_. |
| 60 | + |
| 61 | +_What is the size of the largest area_ that isn't infinite? |
| 62 | + |
| 63 | +----------------- |
| 64 | + |
| 65 | +## --- Part Two --- |
| 66 | + |
| 67 | +On the other hand, _if the coordinates are safe_, maybe the best you can do is try to find a _region_ near as many coordinates as possible. |
| 68 | + |
| 69 | +For example, suppose you want the sum of the [Manhattan distance](https://en.wikipedia.org/wiki/Taxicab_geometry) to all of the coordinates to be _less than 32_. For each location, add up the distances to all of the given coordinates; if the total of those distances is less than 32, that location is within the desired region. Using the same coordinates as above, the resulting region looks like this: |
| 70 | + |
| 71 | + .......... |
| 72 | + .A........ |
| 73 | + .......... |
| 74 | + ...###..C. |
| 75 | + ..#D###... |
| 76 | + ..###E#... |
| 77 | + .B.###.... |
| 78 | + .......... |
| 79 | + .......... |
| 80 | + ........F. |
| 81 | + |
| 82 | + |
| 83 | +In particular, consider the highlighted location `4,3` located at the top middle of the region. Its calculation is as follows, where `abs()` is the [absolute value](https://en.wikipedia.org/wiki/Absolute_value) function: |
| 84 | + |
| 85 | +* Distance to coordinate A: `abs(4-1) + abs(3-1) = 5` |
| 86 | +* Distance to coordinate B: `abs(4-1) + abs(3-6) = 6` |
| 87 | +* Distance to coordinate C: `abs(4-8) + abs(3-3) = 4` |
| 88 | +* Distance to coordinate D: `abs(4-3) + abs(3-4) = 2` |
| 89 | +* Distance to coordinate E: `abs(4-5) + abs(3-5) = 3` |
| 90 | +* Distance to coordinate F: `abs(4-8) + abs(3-9) = 10` |
| 91 | +* Total distance: `5 + 6 + 4 + 2 + 3 + 10 = 30` |
| 92 | + |
| 93 | +Because the total distance to all coordinates (`30`) is less than 32, the location is _within_ the region. |
| 94 | + |
| 95 | +This region, which also includes coordinates D and E, has a total size of _16_. |
| 96 | + |
| 97 | +Your actual region will need to be much larger than this example, though, instead including all locations with a total distance of less than _10000_. |
| 98 | + |
| 99 | +_What is the size of the region containing all locations which have a total distance to all given coordinates of less than 10000?_ |
0 commit comments