The distress signal leads you to a large network of tunnels.
You can’t search them all manually.
Your backpack has a series of sensors that by the power of wintery magic or something, fly off into the tunnels and come to rest.
Each sensor records the coordinate of the nearest beacon it receives a signal from.
Today’s input is a list of sensor positions paired with the position of its closest beacon.
Yup! We’re dealing with sets of coordinates that fit on a perfectly rectangular plane again.
Because each sensor only identifies its closest beacon,
if a sensor detects a beacon, you know there are no other beacons that close or closer to that sensor
The distress signal isn’t coming from any of the detected beacons.
It must be coming from a beacon that’s not the closest beacon for any sensor.
The question asks how many positions cannot contain a beacon on the row y=2000000.
Staring off with a decently filled out bit of skeleton code:
Helpers
A function to help determine how many coordinates are covered on a certain row given a combo of sensor and beacon:
A method on Coord to determine the manhattan distance to an other Coord:
The remaining question is how to combine the ranges on a single row for all beacons in the input.
Pluggin everything into our skeletoncode, and that’s part1!
Final code
Part 2
The distress beacon is not detected by any sensor,
but the distress beacon must have x and y coordinates each no lower than 0 and no larger than 4000000.
The question asks what the tuning frequency of the distress beacon is.
A tuning frequency can be found by multiplying a beacon’s x coordinate by 4000000 and then adding its y coordinate.
The question is set up so there’s a single gap in the coverage of sensors, that’s where the distress beacon is.
So the question is asking to find that single coordinate in the given range that isn’t covered.