/**
 * Given a list of tuples, replace the nth element of each tuple with a new value.
 *
 * @param tupleList A list of tuples.
 * @param index The index representing the element to replace.
 * @param newValue The new value to replace the element with.
 * @return A list of tuples with the nth element replaced.
 *
 * Example:
 * replaceNthElement(listOf(1, 2, 3), 1, "X") => listOf("X", 2, 3)
 */
fun replaceNthElement(tupleList: List<List<Any>>, index: Int, newValue: Any): List<List<Any>> {

    // Use map to iterate over tupleList and replace the nth element in each tuple
    return tupleList.map { tuple ->
        tuple.mapIndexed { i, value ->
            if (i == index) newValue else value
        }
    }
}
/**
 * Given a list of tuples, replace the nth element of each tuple with a new value.
 *
 * @param tupleList A list of tuples.
 * @param index The index representing the element to replace.
 * @param newValue The new value to replace the element with.
 * @return A list of tuples with the nth element replaced.
 *
 * Example:
 * replaceNthElement(listOf(1, 2, 3), 1, "X") => listOf("X", 2, 3)
 */
fun replaceNthElement(tupleList: List<List<Any>>, index: Int, newValue: Any): List<List<Any>> {
/**
 * Given a list of tuples, replace the nth element of each tuple with a new value.
 *
 * @param tupleList A list of tuples.
 * @param index The index representing the element to replace.
 * @param newValue The new value to replace the element with.
 * @return A list of tuples with the nth element replaced.
 *
 * Example:
 * replaceNthElement(listOf(1, 2, 3), 1, "X") => listOf("X", 2, 3)
 */
fun replaceNthElement(tupleList: List<List<Any>>, index: Int, newValue: Any): List<List<Any>> {

    // Use map to iterate over tupleList and replace the nth element in each tuple
    return tupleList.map { tuple ->
        tuple.mapIndexed { i, value ->
            if (i == index) newValue else value
        }
    }
}