/**
 * This function calculates the average speed of an athlete based on the given distance and time.
 * The distance is a floating-point number indicating the total distance covered by the athlete, in meters.
 * The time is a triple containing three floating-point numbers representing the hours, minutes, and seconds taken by the athlete.
 *
 * Write a code to convert the time triple into a total number of seconds.
 * Then, calculate the average speed by dividing the distance by the total number of seconds.
 * The result should be rounded to 2 decimal places.
 *
 * Example:
 * calculateAverageSpeed(800.0, Triple(0.0, 2.5, 30.0))
 * Output: 5.93 (rounded to 2 decimal places)
 */
fun calculateAverageSpeed(distance: Double, time: Triple<Double, Double, Double>): Double {

    // Convert time triple to seconds
    val totalSeconds = time.first * 3600 + time.second * 60 + time.third

    // Calculate average speed
    val averageSpeed = (distance / totalSeconds).toDouble().round(2)

    return averageSpeed
}

fun Double.round(decimals: Int): Double {
    var multiplier = 1.0
    repeat(decimals) { multiplier *= 10 }
    return kotlin.math.round(this * multiplier) / multiplier
}
/**
 * This function calculates the average speed of an athlete based on the given distance and time.
 * The distance is a floating-point number indicating the total distance covered by the athlete, in meters.
 * The time is a triple containing three floating-point numbers representing the hours, minutes, and seconds taken by the athlete.
 *
 * Write a code to convert the time triple into a total number of seconds.
 * Then, calculate the average speed by dividing the distance by the total number of seconds.
 * The result should be rounded to 2 decimal places.
 *
 * Example:
 * calculateAverageSpeed(800.0, Triple(0.0, 2.5, 30.0))
 * Output: 5.93 (rounded to 2 decimal places)
 */
fun calculateAverageSpeed(distance: Double, time: Triple<Double, Double, Double>): Double {
/**
 * This function calculates the average speed of an athlete based on the given distance and time.
 * The distance is a floating-point number indicating the total distance covered by the athlete, in meters.
 * The time is a triple containing three floating-point numbers representing the hours, minutes, and seconds taken by the athlete.
 *
 * Write a code to convert the time triple into a total number of seconds.
 * Then, calculate the average speed by dividing the distance by the total number of seconds.
 * The result should be rounded to 2 decimal places.
 *
 * Example:
 * calculateAverageSpeed(800.0, Triple(0.0, 2.5, 30.0))
 * Output: 5.93 (rounded to 2 decimal places)
 */
fun calculateAverageSpeed(distance: Double, time: Triple<Double, Double, Double>): Double {

    // Convert time triple to seconds
    val totalSeconds = time.first * 3600 + time.second * 60 + time.third

    // Calculate average speed
    val averageSpeed = (distance / totalSeconds).toDouble().round(2)

    return averageSpeed
}

fun Double.round(decimals: Int): Double {
    var multiplier = 1.0
    repeat(decimals) { multiplier *= 10 }
    return kotlin.math.round(this * multiplier) / multiplier
}