/**
 * Given a tuple, replace a slice of elements with another tuple.
 *
 * @param tup The original tuple.
 * @param startIdx The starting index of the slice to be replaced.
 * @param endIdx The ending index (exclusive) of the slice to be replaced.
 * @param replacementTup The tuple containing elements to replace the slice.
 * @return The new tuple with the specified slice replaced by elements from the replacement tuple.
 */
fun replaceTupleElements(tup: List<Any>, startIdx: Int, endIdx: Int, replacementTup: List<Any>): List<Any> {

    // Convert the original tuple to a mutable list for ease of manipulation
    val lst = tup.toMutableList()

    // Replace the slice with the elements from the replacement tuple
    lst.subList(startIdx, endIdx).clear()
    lst.addAll(startIdx, replacementTup)

    return lst
}

// Exercise usage example
val originalTuple = listOf(1, 2, 3, 4, 5)
val startIndex = 1
val endIndex = 4
val replacementTuple = listOf('a', 'b', 'c', 'd')
/**
 * Given a tuple, replace a slice of elements with another tuple.
 *
 * @param tup The original tuple.
 * @param startIdx The starting index of the slice to be replaced.
 * @param endIdx The ending index (exclusive) of the slice to be replaced.
 * @param replacementTup The tuple containing elements to replace the slice.
 * @return The new tuple with the specified slice replaced by elements from the replacement tuple.
 */
fun replaceTupleElements(tup: List<Any>, startIdx: Int, endIdx: Int, replacementTup: List<Any>): List<Any> {
/**
 * Given a tuple, replace a slice of elements with another tuple.
 *
 * @param tup The original tuple.
 * @param startIdx The starting index of the slice to be replaced.
 * @param endIdx The ending index (exclusive) of the slice to be replaced.
 * @param replacementTup The tuple containing elements to replace the slice.
 * @return The new tuple with the specified slice replaced by elements from the replacement tuple.
 */
fun replaceTupleElements(tup: List<Any>, startIdx: Int, endIdx: Int, replacementTup: List<Any>): List<Any> {

    // Convert the original tuple to a mutable list for ease of manipulation
    val lst = tup.toMutableList()

    // Replace the slice with the elements from the replacement tuple
    lst.subList(startIdx, endIdx).clear()
    lst.addAll(startIdx, replacementTup)

    return lst
}

// Exercise usage example
val originalTuple = listOf(1, 2, 3, 4, 5)
val startIndex = 1
val endIndex = 4
val replacementTuple = listOf('a', 'b', 'c', 'd')