/**
 * This exercise aims to test the practical application of loops with sets and accessing tuple elements.
 * Given two sets and an index value, the task is to find the intersection of the elements at that index within the tuples
 * present in both sets. The function should return a set containing the common elements.
 *
 * @param set1 First set containing tuples.
 * @param set2 Second set containing tuples.
 * @param tupleIndex Index of elements to be compared within the tuples.
 * @return Intersection of elements at the specified index within the tuples in set1 and set2.
 */
fun intersectionOfSetsWithLoopMath(set1: Set<Pair<Int, Int>>, set2: Set<Pair<Int, Int>>, tupleIndex: Int): Set<Int> {

    // Create an empty set to store the intersection
    val intersectionSet = mutableSetOf<Int>()

    // Iterate over each tuple in set1
    for (tuple1 in set1) {
        // Iterate over each tuple in set2
        for (tuple2 in set2) {
            // Check if the elements at the specified index match
            if (tuple1.toList()[tupleIndex] == tuple2.toList()[tupleIndex]) {
                // Add the matching element to the intersection set
                intersectionSet.add(tuple1.toList()[tupleIndex])
            }
        }
    }

    return intersectionSet
}
/**
 * This exercise aims to test the practical application of loops with sets and accessing tuple elements.
 * Given two sets and an index value, the task is to find the intersection of the elements at that index within the tuples
 * present in both sets. The function should return a set containing the common elements.
 *
 * @param set1 First set containing tuples.
 * @param set2 Second set containing tuples.
 * @param tupleIndex Index of elements to be compared within the tuples.
 * @return Intersection of elements at the specified index within the tuples in set1 and set2.
 */
fun intersectionOfSetsWithLoopMath(set1: Set<Pair<Int, Int>>, set2: Set<Pair<Int, Int>>, tupleIndex: Int): Set<Int> {
/**
 * This exercise aims to test the practical application of loops with sets and accessing tuple elements.
 * Given two sets and an index value, the task is to find the intersection of the elements at that index within the tuples
 * present in both sets. The function should return a set containing the common elements.
 *
 * @param set1 First set containing tuples.
 * @param set2 Second set containing tuples.
 * @param tupleIndex Index of elements to be compared within the tuples.
 * @return Intersection of elements at the specified index within the tuples in set1 and set2.
 */
fun intersectionOfSetsWithLoopMath(set1: Set<Pair<Int, Int>>, set2: Set<Pair<Int, Int>>, tupleIndex: Int): Set<Int> {

    // Create an empty set to store the intersection
    val intersectionSet = mutableSetOf<Int>()

    // Iterate over each tuple in set1
    for (tuple1 in set1) {
        // Iterate over each tuple in set2
        for (tuple2 in set2) {
            // Check if the elements at the specified index match
            if (tuple1.toList()[tupleIndex] == tuple2.toList()[tupleIndex]) {
                // Add the matching element to the intersection set
                intersectionSet.add(tuple1.toList()[tupleIndex])
            }
        }
    }

    return intersectionSet
}