/// <summary> /// Gets the number of unique houses that Santa delivers at least one present to. /// </summary> /// <param name="instructions">The instructions Santa should follow.</param> /// <returns>The number of unique houses that receive a delivery of at least one present.</returns> internal static int GetUniqueHousesVisitedBySanta(string instructions) { var directions = GetDirections(instructions); var santa = new SantaGps(); var coordinates = new HashSet <Point>(); foreach (var direction in directions) { coordinates.Add(santa.Location); santa.Move(direction); } return(coordinates.Count); }
/// <summary> /// Gets the number of unique houses that Santa delivers at least one present to. /// </summary> /// <param name="instructions">The instructions Santa should follow.</param> /// <returns>The number of unique houses that receive a delivery of at least one present.</returns> internal static int GetUniqueHousesVisitedBySanta(string instructions) { ICollection<CardinalDirection> directions = GetDirections(instructions); var santa = new SantaGps(); var coordinates = new List<Point>(); foreach (var direction in directions) { if (!coordinates.Contains(santa.Location)) { coordinates.Add(santa.Location); } santa.Move(direction); } return coordinates.Count; }
/// <summary> /// Gets the number of unique houses that Santa and Robo-Santa deliver at least one present to. /// </summary> /// <param name="instructions">The instructions that Santa and Robo-Santa should follow.</param> /// <returns>The number of unique houses that receive a delivery of at least one present.</returns> internal static int GetUniqueHousesVisitedBySantaAndRoboSanta(string instructions) { ICollection<CardinalDirection> directions = GetDirections(instructions); var santa = new SantaGps(); var roboSanta = new SantaGps(); var current = santa; var coordinates = new List<Point>(); foreach (var direction in directions) { current.Move(direction); if (current.Location != Point.Empty && !coordinates.Contains(current.Location)) { coordinates.Add(current.Location); } current = current == santa ? roboSanta : santa; } return coordinates.Count + 1; }
/// <summary> /// Gets the number of unique houses that Santa and Robo-Santa deliver at least one present to. /// </summary> /// <param name="instructions">The instructions that Santa and Robo-Santa should follow.</param> /// <returns>The number of unique houses that receive a delivery of at least one present.</returns> internal static int GetUniqueHousesVisitedBySantaAndRoboSanta(string instructions) { var directions = GetDirections(instructions); var santa = new SantaGps(); var roboSanta = new SantaGps(); var current = santa; var coordinates = new HashSet <Point>(); foreach (var direction in directions) { current.Move(direction); if (current.Location != Point.Empty) { coordinates.Add(current.Location); } current = current == santa ? roboSanta : santa; } return(coordinates.Count + 1); }