Esempio n. 1
0
        public int DistanceAfterTime(Reindeer reindeer, int time)
        {
            var totalCycleTime = reindeer.FlightTime + reindeer.RestTime;

            var fullCyleTime     = (reindeer.FlightTime * (time / totalCycleTime));
            var partialCycleTime = (int)Math.Min(reindeer.FlightTime, (double)(time % totalCycleTime));

            return((fullCyleTime + partialCycleTime) * reindeer.Speed);
        }
Esempio n. 2
0
        private static int CalculateDistance(Reindeer reindeer, int duration)
        {
            int totalTime     = 0;
            int totalDistance = 0;

            while (totalTime < duration)
            {
                if ((duration - totalTime) < reindeer.time)
                {
                    totalDistance += reindeer.speed * (duration - totalTime);
                    return(totalDistance);
                }
                else
                {
                    totalDistance += reindeer.speed * reindeer.time;
                    totalTime     += reindeer.time;
                }

                totalTime += reindeer.rest;
            }

            return(totalDistance);
        }