adventofcode/2018/day06/problem

148 lines
4.8 KiB
Plaintext
Raw Normal View History

2018-12-06 17:22:55 +00:00
Advent of Code
--- Day 6: Chronal Coordinates ---
2019-11-08 21:01:07 +00:00
The device on your wrist beeps several times, and once again you feel like
you're falling.
2018-12-06 17:22:55 +00:00
2019-11-08 21:01:07 +00:00
"Situation critical," the device announces. "Destination indeterminate.
Chronal interference detected. Please specify new target coordinates."
2018-12-06 17:22:55 +00:00
2019-11-08 21:01:07 +00:00
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.
2018-12-06 17:22:55 +00:00
2019-11-08 21:01:07 +00:00
If they're dangerous, maybe you can minimize the danger by finding the
coordinate that gives the largest distance from the other points.
2018-12-06 17:22:55 +00:00
2019-11-08 21:01:07 +00:00
Using only the Manhattan distance, determine the area around each coordinate
by counting the number of integer X,Y locations that are closest to that
coordinate (and aren't tied in distance to any other coordinate).
2018-12-06 17:22:55 +00:00
2019-11-08 21:01:07 +00:00
Your goal is to find the size of the largest area that isn't infinite. For
example, consider the following list of coordinates:
2018-12-06 17:22:55 +00:00
1, 1
1, 6
8, 3
3, 4
5, 5
8, 9
2019-11-08 21:01:07 +00:00
If we name these coordinates A through F, we can draw them on a grid,
putting 0,0 at the top left:
2018-12-06 17:22:55 +00:00
..........
.A........
..........
........C.
...D......
.....E....
.B........
..........
..........
........F.
2019-11-08 21:01:07 +00:00
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:
2018-12-06 17:22:55 +00:00
aaaaa.cccc
aAaaa.cccc
aaaddecccc
aadddeccCc
..dDdeeccc
bb.deEeecc
bBb.eeee..
bbb.eeefff
bbb.eeffff
bbb.ffffFf
2019-11-08 21:01:07 +00:00
Locations shown as . are equally far from two or more coordinates, and so
they don't count as being closest to any.
2018-12-06 17:22:55 +00:00
2019-11-08 21:01:07 +00:00
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.
2018-12-06 17:22:55 +00:00
What is the size of the largest area that isn't infinite?
Your puzzle answer was 3989.
--- Part Two ---
2019-11-08 21:01:07 +00:00
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.
2018-12-06 17:22:55 +00:00
2019-11-08 21:01:07 +00:00
For example, suppose you want the sum of the Manhattan distance 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:
2018-12-06 17:22:55 +00:00
..........
.A........
..........
...###..C.
..#D###...
..###E#...
.B.###....
..........
..........
........F.
2019-11-08 21:01:07 +00:00
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 function:
2018-12-06 17:22:55 +00:00
 Distance to coordinate A: abs(4-1) + abs(3-1) =  5
 Distance to coordinate B: abs(4-1) + abs(3-6) =  6
 Distance to coordinate C: abs(4-8) + abs(3-3) =  4
 Distance to coordinate D: abs(4-3) + abs(3-4) =  2
 Distance to coordinate E: abs(4-5) + abs(3-5) =  3
 Distance to coordinate F: abs(4-8) + abs(3-9) = 10
 Total distance: 5 + 6 + 4 + 2 + 3 + 10 = 30
2019-11-08 21:01:07 +00:00
Because the total distance to all coordinates (30) is less than 32, the
location is within the region.
2018-12-06 17:22:55 +00:00
2019-11-08 21:01:07 +00:00
This region, which also includes coordinates D and E, has a total size of
16.
2018-12-06 17:22:55 +00:00
2019-11-08 21:01:07 +00:00
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.
2018-12-06 17:22:55 +00:00
2019-11-08 21:01:07 +00:00
What is the size of the region containing all locations which have a total
distance to all given coordinates of less than 10000?
2018-12-06 17:22:55 +00:00
Your puzzle answer was 49715.
Both parts of this puzzle are complete! They provide two gold stars: **
References
Visible links
. https://adventofcode.com/
. https://adventofcode.com/2018/about
. https://adventofcode.com/2018/events
. https://teespring.com/adventofcode
. https://adventofcode.com/2018/settings
. https://adventofcode.com/2018/auth/logout
. Advent of Code Supporter
https://adventofcode.com/2018/support
. https://adventofcode.com/2018
. https://adventofcode.com/2018
. https://adventofcode.com/2018/support
. https://adventofcode.com/2018/sponsors
. https://adventofcode.com/2018/leaderboard
. https://adventofcode.com/2018/stats
. https://adventofcode.com/2018/sponsors
. https://en.wikipedia.org/wiki/Taxicab_geometry
. https://en.wikipedia.org/wiki/Integer
. https://en.wikipedia.org/wiki/Taxicab_geometry
. https://en.wikipedia.org/wiki/Absolute_value
. https://adventofcode.com/2018
. https://adventofcode.com/2018/day/6/input