/**
 * Given two sets of floating-point numbers, numbers1 and numbers2,
 * this function finds the intersection of the two sets by rounding
 * each number to three decimal places and checking if the rounded numbers
 * are equal. Returns a list of the common numbers rounded to three decimal places.
 *
 * @param numbers1 A list of floating-point numbers, e.g. [1.23456, 2.34567, 3.45678]
 * @param numbers2 A list of floating-point numbers, e.g. [2.56789, 3.67890, 4.78901]
 * @return A list of common numbers rounded to three decimal places.
 */
fun findIntersection(numbers1: List<Double>, numbers2: List<Double>): List<Double> {

    val commonNumbers = mutableListOf<Double>()

    for (num1 in numbers1) {
        val roundedNum1 = num1.round(3)
        for (num2 in numbers2) {
            val roundedNum2 = num2.round(3)
            if (roundedNum1 == roundedNum2) {
                commonNumbers.add(roundedNum1)
            }
        }
    }

    return commonNumbers
}

fun Double.round(decimals: Int): Double = "%.${decimals}f".format(this).toDouble()
/**
 * Given two sets of floating-point numbers, numbers1 and numbers2,
 * this function finds the intersection of the two sets by rounding
 * each number to three decimal places and checking if the rounded numbers
 * are equal. Returns a list of the common numbers rounded to three decimal places.
 *
 * @param numbers1 A list of floating-point numbers, e.g. [1.23456, 2.34567, 3.45678]
 * @param numbers2 A list of floating-point numbers, e.g. [2.56789, 3.67890, 4.78901]
 * @return A list of common numbers rounded to three decimal places.
 */
fun findIntersection(numbers1: List<Double>, numbers2: List<Double>): List<Double> {
/**
 * Given two sets of floating-point numbers, numbers1 and numbers2,
 * this function finds the intersection of the two sets by rounding
 * each number to three decimal places and checking if the rounded numbers
 * are equal. Returns a list of the common numbers rounded to three decimal places.
 *
 * @param numbers1 A list of floating-point numbers, e.g. [1.23456, 2.34567, 3.45678]
 * @param numbers2 A list of floating-point numbers, e.g. [2.56789, 3.67890, 4.78901]
 * @return A list of common numbers rounded to three decimal places.
 */
fun findIntersection(numbers1: List<Double>, numbers2: List<Double>): List<Double> {

    val commonNumbers = mutableListOf<Double>()

    for (num1 in numbers1) {
        val roundedNum1 = num1.round(3)
        for (num2 in numbers2) {
            val roundedNum2 = num2.round(3)
            if (roundedNum1 == roundedNum2) {
                commonNumbers.add(roundedNum1)
            }
        }
    }

    return commonNumbers
}

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