/**
 * Given two tuples (tuple1 and tuple2), return a tuple containing the elements that are common in both tuples.
 * Solve the exercise using tuple methods and negative indexing.
 *
 * @param tuple1 The first tuple.
 * @param tuple2 The second tuple.
 * @return A tuple containing the common elements in both tuples.
 *
 * Example:
 * tupleIntersection(listOf('a', 'b', 'c', 'd', 'e', 'f'), listOf('c', 'd', 'e', 'f', 'g', 'h'))
 * Output: ['c', 'd', 'e', 'f']
 */
fun tupleIntersection(tuple1: List<Any>, tuple2: List<Any>): List<Any> {

    val commonElements = mutableListOf<Any>()

    // Iterate over the elements of tuple1
    for (i in tuple1.indices) {
        // Check if the element exists in tuple2 using negative indexing
        if (tuple1[i] in tuple2.subList(tuple2.size - tuple1.size + i, tuple2.size)) {
            commonElements.add(tuple1[i])
        }
    }

    return commonElements
}
/**
 * Given two tuples (tuple1 and tuple2), return a tuple containing the elements that are common in both tuples.
 * Solve the exercise using tuple methods and negative indexing.
 *
 * @param tuple1 The first tuple.
 * @param tuple2 The second tuple.
 * @return A tuple containing the common elements in both tuples.
 *
 * Example:
 * tupleIntersection(listOf('a', 'b', 'c', 'd', 'e', 'f'), listOf('c', 'd', 'e', 'f', 'g', 'h'))
 * Output: ['c', 'd', 'e', 'f']
 */
fun tupleIntersection(tuple1: List<Any>, tuple2: List<Any>): List<Any> {
/**
 * Given two tuples (tuple1 and tuple2), return a tuple containing the elements that are common in both tuples.
 * Solve the exercise using tuple methods and negative indexing.
 *
 * @param tuple1 The first tuple.
 * @param tuple2 The second tuple.
 * @return A tuple containing the common elements in both tuples.
 *
 * Example:
 * tupleIntersection(listOf('a', 'b', 'c', 'd', 'e', 'f'), listOf('c', 'd', 'e', 'f', 'g', 'h'))
 * Output: ['c', 'd', 'e', 'f']
 */
fun tupleIntersection(tuple1: List<Any>, tuple2: List<Any>): List<Any> {

    val commonElements = mutableListOf<Any>()

    // Iterate over the elements of tuple1
    for (i in tuple1.indices) {
        // Check if the element exists in tuple2 using negative indexing
        if (tuple1[i] in tuple2.subList(tuple2.size - tuple1.size + i, tuple2.size)) {
            commonElements.add(tuple1[i])
        }
    }

    return commonElements
}