/**
 * Calculate the remaining distance the athlete must cover 
 * to reach their goal, considering the distances covered 
 * by the athlete so far.
 *
 * @param goalDistance The total distance the athlete wants to cover.
 * @param athleteDistances A set containing the distances covered by the athlete.
 * @return The remaining distance the athlete needs to cover to reach their goal.
 */
fun calculateGoalDistance(goalDistance: Double, athleteDistances: Set<Double>): Double {

    var remainingDistance = goalDistance  // Initially set remaining distance equal to the goal distance

    // Iterate over each distance covered by the athlete
    for (distance in athleteDistances) {
        if (distance >= goalDistance) {
            // If the distance covered is equal to or greater than the goal distance, break out of the loop
            break
        }
        
        // If the distance covered is less than the goal distance, subtract it from the remaining distance
        remainingDistance -= distance
    }

    return remainingDistance
}

// Example usage
val athleteGoalDistance = 1000.0  // The athlete wants to cover a distance of 1000 meters
val athleteDistancesCovered = setOf(200.0, 350.0, 400.0, 150.0, 300.0, 200.0)
/**
 * Calculate the remaining distance the athlete must cover 
 * to reach their goal, considering the distances covered 
 * by the athlete so far.
 *
 * @param goalDistance The total distance the athlete wants to cover.
 * @param athleteDistances A set containing the distances covered by the athlete.
 * @return The remaining distance the athlete needs to cover to reach their goal.
 */
fun calculateGoalDistance(goalDistance: Double, athleteDistances: Set<Double>): Double {
/**
 * Calculate the remaining distance the athlete must cover 
 * to reach their goal, considering the distances covered 
 * by the athlete so far.
 *
 * @param goalDistance The total distance the athlete wants to cover.
 * @param athleteDistances A set containing the distances covered by the athlete.
 * @return The remaining distance the athlete needs to cover to reach their goal.
 */
fun calculateGoalDistance(goalDistance: Double, athleteDistances: Set<Double>): Double {

    var remainingDistance = goalDistance  // Initially set remaining distance equal to the goal distance

    // Iterate over each distance covered by the athlete
    for (distance in athleteDistances) {
        if (distance >= goalDistance) {
            // If the distance covered is equal to or greater than the goal distance, break out of the loop
            break
        }
        
        // If the distance covered is less than the goal distance, subtract it from the remaining distance
        remainingDistance -= distance
    }

    return remainingDistance
}

// Example usage
val athleteGoalDistance = 1000.0  // The athlete wants to cover a distance of 1000 meters
val athleteDistancesCovered = setOf(200.0, 350.0, 400.0, 150.0, 300.0, 200.0)