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); }
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); }