/**
 * Given two tuples t1 and t2 representing two number lines, 
 * this function returns a new tuple where each value represents the intersection 
 * of the corresponding values in t1 and t2.
 *
 * @param t1 The first number line represented as a tuple
 * @param t2 The second number line represented as a tuple
 * @return A new tuple representing the intersection of t1 and t2
 */
fun addTupleValues(t1: List<Pair<Int, Int>>, t2: List<Pair<Int, Int>>): List<Pair<Int, Int>> {

    val intersection = mutableListOf<Pair<Int, Int>>()
    for (i in t1.indices) {
        for (j in t2.indices) {
            if (t1[i].first <= t2[j].first && t2[j].first <= t1[i].second) {
                intersection.add(Pair(maxOf(t1[i].first, t2[j].first), minOf(t1[i].second, t2[j].second)))
            } else if (t2[j].first <= t1[i].first && t1[i].first <= t2[j].second) {
                intersection.add(Pair(maxOf(t1[i].first, t2[j].first), minOf(t1[i].second, t2[j].second)))
            }
        }
    }
    return intersection
}
/**
 * Given two tuples t1 and t2 representing two number lines, 
 * this function returns a new tuple where each value represents the intersection 
 * of the corresponding values in t1 and t2.
 *
 * @param t1 The first number line represented as a tuple
 * @param t2 The second number line represented as a tuple
 * @return A new tuple representing the intersection of t1 and t2
 */
fun addTupleValues(t1: List<Pair<Int, Int>>, t2: List<Pair<Int, Int>>): List<Pair<Int, Int>> {
/**
 * Given two tuples t1 and t2 representing two number lines, 
 * this function returns a new tuple where each value represents the intersection 
 * of the corresponding values in t1 and t2.
 *
 * @param t1 The first number line represented as a tuple
 * @param t2 The second number line represented as a tuple
 * @return A new tuple representing the intersection of t1 and t2
 */
fun addTupleValues(t1: List<Pair<Int, Int>>, t2: List<Pair<Int, Int>>): List<Pair<Int, Int>> {

    val intersection = mutableListOf<Pair<Int, Int>>()
    for (i in t1.indices) {
        for (j in t2.indices) {
            if (t1[i].first <= t2[j].first && t2[j].first <= t1[i].second) {
                intersection.add(Pair(maxOf(t1[i].first, t2[j].first), minOf(t1[i].second, t2[j].second)))
            } else if (t2[j].first <= t1[i].first && t1[i].first <= t2[j].second) {
                intersection.add(Pair(maxOf(t1[i].first, t2[j].first), minOf(t1[i].second, t2[j].second)))
            }
        }
    }
    return intersection
}