Ejemplo n.º 1
0
    /// <summary>
    /// Gets the maximum number of points for the reindeer at the specified time index.
    /// </summary>
    /// <param name="flightData">The reindeer flight data.</param>
    /// <param name="timeIndex">The time index.</param>
    /// <returns>
    /// The maximum number of points for a reindeer at the time index specified by <paramref name="timeIndex"/>.
    /// </returns>
    internal static int GetMaximumPointsOfFastestReindeer(ICollection <string> flightData, int timeIndex)
    {
        var data = flightData
                   .Select((p) => FlightData.Parse(p))
                   .ToList();

        var scoreboard = data.ToDictionary((p) => p.Name, (p) => 0);

        for (int i = 1; i < timeIndex; i++)
        {
            // Find how far each reindeer is from the starting point
            var distances = data.ToDictionary((p) => p.Name, (p) => p.GetDistanceAfterTimeIndex(i));

            // Find the furthest distance away one or more reindeer are
            int maxDistance = distances.Max((p) => p.Value);

            // Award each reindeer who is that distance away a point
            foreach (var reindeer in distances.Where((p) => p.Value == maxDistance))
            {
                scoreboard[reindeer.Key]++;
            }
        }

        return(scoreboard
               .Select((p) => p.Value)
               .Max());
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Gets the maximum distance travelled by the specified reindeer at the specified time index.
    /// </summary>
    /// <param name="flightData">The reindeer flight data.</param>
    /// <param name="timeIndex">The time index.</param>
    /// <returns>
    /// The maximum distance travelled by a reindeer at the time index specified by <paramref name="timeIndex"/>.
    /// </returns>
    internal static int GetMaximumDistanceOfFastestReindeer(ICollection <string> flightData, int timeIndex)
    {
        var data = flightData
                   .Select((p) => FlightData.Parse(p))
                   .ToList();

        return(data
               .Select((p) => p.GetDistanceAfterTimeIndex(timeIndex))
               .Max());
    }