/**
 * Given a list of nested tuples, called tuples, implement a function filterEvenNumbers that will
 * iterate through each tuple, check the value of each element, and return a new list of tuples
 * that contain only even numbers.
 *
 * @param tuples A list of nested tuples.
 * @return A new list of nested tuples that contain only even numbers.
 *
 * Example:
 * filterEvenNumbers(listOf(Pair("Sam", Triple(1, 2, 3)), Pair("Alice", Triple(4, 5, 6)), Pair("Bob", Triple(7, 8, 9)))
 * => listOf(Pair("Alice", Triple(4, 6)), Pair("Bob", Triple(8)))
 */
fun filterEvenNumbers(tuples: List<Pair<String, Triple<Int, Int, Int>>>): List<Pair<String, Triple<Int, Int, Int>>> {

    val result = mutableListOf<Pair<String, Triple<Int, Int, Int>>>()

    for (tuple in tuples) {
        val filteredTuple = mutableListOf<Int>()
        for (element in tuple.second.toList()) {
            if (element % 2 == 0) {
                filteredTuple.add(element)
            }
        }
        if (filteredTuple.isNotEmpty()) {
            val tuple2 = Pair(tuple.first, Triple(filteredTuple[0], filteredTuple.getOrElse(1) { 0 }, filteredTuple.getOrElse(2) { 0 }))
            result.add(tuple2)
        }
    }

    return result
}
/**
 * Given a list of nested tuples, called tuples, implement a function filterEvenNumbers that will
 * iterate through each tuple, check the value of each element, and return a new list of tuples
 * that contain only even numbers.
 *
 * @param tuples A list of nested tuples.
 * @return A new list of nested tuples that contain only even numbers.
 *
 * Example:
 * filterEvenNumbers(listOf(Pair("Sam", Triple(1, 2, 3)), Pair("Alice", Triple(4, 5, 6)), Pair("Bob", Triple(7, 8, 9)))
 * => listOf(Pair("Alice", Triple(4, 6)), Pair("Bob", Triple(8)))
 */
fun filterEvenNumbers(tuples: List<Pair<String, Triple<Int, Int, Int>>>): List<Pair<String, Triple<Int, Int, Int>>> {
/**
 * Given a list of nested tuples, called tuples, implement a function filterEvenNumbers that will
 * iterate through each tuple, check the value of each element, and return a new list of tuples
 * that contain only even numbers.
 *
 * @param tuples A list of nested tuples.
 * @return A new list of nested tuples that contain only even numbers.
 *
 * Example:
 * filterEvenNumbers(listOf(Pair("Sam", Triple(1, 2, 3)), Pair("Alice", Triple(4, 5, 6)), Pair("Bob", Triple(7, 8, 9)))
 * => listOf(Pair("Alice", Triple(4, 6)), Pair("Bob", Triple(8)))
 */
fun filterEvenNumbers(tuples: List<Pair<String, Triple<Int, Int, Int>>>): List<Pair<String, Triple<Int, Int, Int>>> {

    val result = mutableListOf<Pair<String, Triple<Int, Int, Int>>>()

    for (tuple in tuples) {
        val filteredTuple = mutableListOf<Int>()
        for (element in tuple.second.toList()) {
            if (element % 2 == 0) {
                filteredTuple.add(element)
            }
        }
        if (filteredTuple.isNotEmpty()) {
            val tuple2 = Pair(tuple.first, Triple(filteredTuple[0], filteredTuple.getOrElse(1) { 0 }, filteredTuple.getOrElse(2) { 0 }))
            result.add(tuple2)
        }
    }

    return result
}