internal Asteroid GetPart2Solution(Asteroid asteroid) { return(_map.GetOrderOfDestruction(asteroid).Skip(199).First()); }
/// <summary> /// A helper function that generates a SortedDictionary containing all valid angles between the source object /// and any neighbour Asteroids. Each angle in the SortedDictionary contains a SortedList sorted on the distance /// between the source and neighrbour object. /// Distance is actualy the square of the distance to avoid the expensive sqrt operation. /// </summary> /// <param name="sourceAsteroid"></param> private SortedDictionary <double, SortedList <double, Asteroid> > GetDictionaryOfNeighbours(Asteroid sourceAsteroid) { SortedDictionary <double, SortedList <double, Asteroid> > anglesWithNeighbors = new SortedDictionary <double, SortedList <double, Asteroid> >(); foreach (Asteroid asteroid in this.Asteroids) { if (asteroid == sourceAsteroid) { continue; } double angle = sourceAsteroid.GetAngle(asteroid); if (anglesWithNeighbors.ContainsKey(angle) == false) { anglesWithNeighbors.Add(angle, new SortedList <double, Asteroid>()); } double distance = Math.Pow(sourceAsteroid.X - asteroid.X, 2) + Math.Pow(sourceAsteroid.Y - asteroid.Y, 2); anglesWithNeighbors[angle].Add(distance, asteroid); } return(anglesWithNeighbors); }