Part 1
In this puzzle, we have a series of 3D-coordinates and ranges. These describe each a nanobot at a certain coordinate and their signal range. We should find the nanobot with the largest signal range and count how many other nanobots are in their signal range. The distance between two nanobots is using the Manhattan distance, so the distance between points p and q is abs(p.x - q.x) + abs(p.y - q.y) + abs(p.z - p.z).
After reading in the input, we search for the nanobot with the largest radius. After getting its radius, we filtered the total list by their distance to this nanobot with the largest signal range. The length of this list was the answer.
Part 2
In part 2, we should find the coordinate which is in range of the most nanobots.
Finding how many nanobots are in range to a specific coordinate is straight forward and done similar to part 1. For finding the coordinate in a 3D-range with the most nanobots in range, we could use three simple loops and take the largest number until now.
But searching the complete range is unfeasable due to how large the search space ist, so we had to reduce it first. We used a coarse search dividing the complete range into finer and finer grids until a complete search was feasable. Each coordinate (x,y,z) started with a range of the smallest coordinate minus radius to largest coordinate plus radius. At each step the range was divided into 2 halves. Going over each nanobot, we count if a nanobots signal reaches into any of the 8 subranges. We then halve the range of one of the coordinates to the half with more nanobot signals.
Once each coordinate range is at most 16 elements large, we could start the complete search for the coordinate with the most signals in range as the answer.
No comments:
Post a Comment