I ended up implementing this part 3 times and comparing running speeds.
Initial implemention was running part 1 up to 4000000 times (stopping when the answer was found). Since my part 1 was fairly fast (using complex numbers to keep track of coordinates and intervals to check which x values for row 2000000 are within range). Duration: 327.97s. Not bad for a 4 line implementation.
Second implementation was after I realized the point we're looking for has to be on at least 4 different borders of sensor ranges. I collected all the border points (at Manhattan Distance of beacon_distance+1), filtered the ones that were on less than 4 borders, and for the points that were left I checked whether they were in range of any sensors. Seemed real smart at the time. Duration: 10+ min. After 10 min I hadn't started the final step yet, and I decided to stop it.
Third implemention is a faster version of the second one. Instead of creating a master list of all border points, I just go over each sensor, get the points on the border, and check for each whether they're in range of any sensors, stopping the program if one is found outside all the ranges. Duration: 3.77s. Baffled that it's such a jump from the second implementation.
TL:DR: Dont' sort or count all the occurances of a list with 85 million coordinates in it.
Want to add to the discussion?
Post a comment!