/**
 * Given a range of values and a list of sets, create a tuple containing the common elements
 * found in all sets, while iterating through the sets.
 *
 * Example:
 * findCommonElements((1..5), listOf(setOf(1, 2, 3), setOf(2, 3, 4), setOf(3, 4, 5))) should return (3).
 *
 * @param range A range of values.
 * @param sets A list of sets.
 * @return A tuple containing the common elements found in all sets.
 */
fun findCommonElements(range: IntRange, sets: List<Set<Int>>): Set<Int> {

    var commonElements = range.toSet() // Initialize with all elements in the range

    // Iterate through the sets
    for (s in sets) {
        commonElements = commonElements.intersect(s) // Find the intersection of common elements and current set
    }

    return commonElements
}
/**
 * Given a range of values and a list of sets, create a tuple containing the common elements
 * found in all sets, while iterating through the sets.
 *
 * Example:
 * findCommonElements((1..5), listOf(setOf(1, 2, 3), setOf(2, 3, 4), setOf(3, 4, 5))) should return (3).
 *
 * @param range A range of values.
 * @param sets A list of sets.
 * @return A tuple containing the common elements found in all sets.
 */
fun findCommonElements(range: IntRange, sets: List<Set<Int>>): Set<Int> {
/**
 * Given a range of values and a list of sets, create a tuple containing the common elements
 * found in all sets, while iterating through the sets.
 *
 * Example:
 * findCommonElements((1..5), listOf(setOf(1, 2, 3), setOf(2, 3, 4), setOf(3, 4, 5))) should return (3).
 *
 * @param range A range of values.
 * @param sets A list of sets.
 * @return A tuple containing the common elements found in all sets.
 */
fun findCommonElements(range: IntRange, sets: List<Set<Int>>): Set<Int> {

    var commonElements = range.toSet() // Initialize with all elements in the range

    // Iterate through the sets
    for (s in sets) {
        commonElements = commonElements.intersect(s) // Find the intersection of common elements and current set
    }

    return commonElements
}