Expand description
§Four-Dimensional Adventure
This problem is the classic union find. However since we only need the count of the distinct sets we can use a much simpler approach.
Starting with an arbitrary point we find all other points within range, adding them to a todo list. We then transitively determine the neighbors of those points, and so on until all sets have been found.