/**
 * Calculates the average density of a set of rock samples using the modulus and division assignment operator.
 *
 * @param sampleLengths A list of the lengths (in cm) of rock samples.
 * @param sampleVolumes A list of the volumes (in cm^3) of rock samples.
 * @return The average density of the rock samples (in g/cm^3).
 */
fun calculateAverageDensity(sampleLengths: List<Int>, sampleVolumes: List<Int>): Double {

    require(sampleLengths.size == sampleVolumes.size) { "Length of lists must be equal" }

    var totalDensity = 0
    for ((length, volume) in sampleLengths.zip(sampleVolumes)) {
        totalDensity += length % volume
    }

    val averageDensity = totalDensity.toDouble() / sampleLengths.size
    return averageDensity.round(4)
}

fun Double.round(decimals: Int): Double = "%.${decimals}f".format(this).toDouble()
/**
 * Calculates the average density of a set of rock samples using the modulus and division assignment operator.
 *
 * @param sampleLengths A list of the lengths (in cm) of rock samples.
 * @param sampleVolumes A list of the volumes (in cm^3) of rock samples.
 * @return The average density of the rock samples (in g/cm^3).
 */
fun calculateAverageDensity(sampleLengths: List<Int>, sampleVolumes: List<Int>): Double {
/**
 * Calculates the average density of a set of rock samples using the modulus and division assignment operator.
 *
 * @param sampleLengths A list of the lengths (in cm) of rock samples.
 * @param sampleVolumes A list of the volumes (in cm^3) of rock samples.
 * @return The average density of the rock samples (in g/cm^3).
 */
fun calculateAverageDensity(sampleLengths: List<Int>, sampleVolumes: List<Int>): Double {

    require(sampleLengths.size == sampleVolumes.size) { "Length of lists must be equal" }

    var totalDensity = 0
    for ((length, volume) in sampleLengths.zip(sampleVolumes)) {
        totalDensity += length % volume
    }

    val averageDensity = totalDensity.toDouble() / sampleLengths.size
    return averageDensity.round(4)
}

fun Double.round(decimals: Int): Double = "%.${decimals}f".format(this).toDouble()