/**
 * Given a tuple, change the value of an element at a specific index.
 *
 * @param tup The original tuple.
 * @param index The index of the element to be changed.
 * @param newValue The new value to be assigned to the element.
 * @return The modified tuple with the element changed.
 *
 * Example:
 * originalTuple = listOf("John", "Smith", 25, "Social Worker")
 * indexToChange = 2
 * newValue = 30
 * changeTupleElement(originalTuple, indexToChange, newValue) // Output: ["John", "Smith", 30, "Social Worker"]
 */
fun changeTupleElement(tup: List<Any>, index: Int, newValue: Any): List<Any> {

    if (index < 0 || index >= tup.size) {
        throw IndexOutOfBoundsException("Invalid index provided.")
    } else {
        val tupleList = tup.toMutableList()
        tupleList[index] = newValue
        return tupleList
    }
}

// Exercise:
/**
 * Given a tuple, change the value of an element at a specific index.
 *
 * @param tup The original tuple.
 * @param index The index of the element to be changed.
 * @param newValue The new value to be assigned to the element.
 * @return The modified tuple with the element changed.
 *
 * Example:
 * originalTuple = listOf("John", "Smith", 25, "Social Worker")
 * indexToChange = 2
 * newValue = 30
 * changeTupleElement(originalTuple, indexToChange, newValue) // Output: ["John", "Smith", 30, "Social Worker"]
 */
fun changeTupleElement(tup: List<Any>, index: Int, newValue: Any): List<Any> {
/**
 * Given a tuple, change the value of an element at a specific index.
 *
 * @param tup The original tuple.
 * @param index The index of the element to be changed.
 * @param newValue The new value to be assigned to the element.
 * @return The modified tuple with the element changed.
 *
 * Example:
 * originalTuple = listOf("John", "Smith", 25, "Social Worker")
 * indexToChange = 2
 * newValue = 30
 * changeTupleElement(originalTuple, indexToChange, newValue) // Output: ["John", "Smith", 30, "Social Worker"]
 */
fun changeTupleElement(tup: List<Any>, index: Int, newValue: Any): List<Any> {

    if (index < 0 || index >= tup.size) {
        throw IndexOutOfBoundsException("Invalid index provided.")
    } else {
        val tupleList = tup.toMutableList()
        tupleList[index] = newValue
        return tupleList
    }
}

// Exercise: