/**
 * Given a tuple, replace the elements from 'start' index to 'end' index with 'newElement'.
 *
 * @param tup The original tuple.
 * @param start The starting index (inclusive) of the range to be replaced.
 * @param end The ending index (exclusive) of the range to be replaced.
 * @param newElement The new element(s) to be inserted in the tuple.
 * @return The modified tuple.
 *
 * Example:
 * replaceTupleElements(listOf(1, 2, 3, 4, 5), 1, 4, listOf('a', 'b', 'c')) -> listOf(1, 'a', 'b', 'c', 5)
 */
fun replaceTupleElements(tup: List<Any>, start: Int, end: Int, newElement: List<Any>): List<Any> {

    // Slicing the tuple from the beginning up to the 'start' index
    val slicedTuple = tup.subList(0, start).toMutableList()

    // Appending the 'newElement' into the sliced part
    slicedTuple.addAll(newElement)

    // Concatenating the sliced part with the remaining elements after 'end' index
    return slicedTuple + tup.subList(end, tup.size)
}
/**
 * Given a tuple, replace the elements from 'start' index to 'end' index with 'newElement'.
 *
 * @param tup The original tuple.
 * @param start The starting index (inclusive) of the range to be replaced.
 * @param end The ending index (exclusive) of the range to be replaced.
 * @param newElement The new element(s) to be inserted in the tuple.
 * @return The modified tuple.
 *
 * Example:
 * replaceTupleElements(listOf(1, 2, 3, 4, 5), 1, 4, listOf('a', 'b', 'c')) -> listOf(1, 'a', 'b', 'c', 5)
 */
fun replaceTupleElements(tup: List<Any>, start: Int, end: Int, newElement: List<Any>): List<Any> {
/**
 * Given a tuple, replace the elements from 'start' index to 'end' index with 'newElement'.
 *
 * @param tup The original tuple.
 * @param start The starting index (inclusive) of the range to be replaced.
 * @param end The ending index (exclusive) of the range to be replaced.
 * @param newElement The new element(s) to be inserted in the tuple.
 * @return The modified tuple.
 *
 * Example:
 * replaceTupleElements(listOf(1, 2, 3, 4, 5), 1, 4, listOf('a', 'b', 'c')) -> listOf(1, 'a', 'b', 'c', 5)
 */
fun replaceTupleElements(tup: List<Any>, start: Int, end: Int, newElement: List<Any>): List<Any> {

    // Slicing the tuple from the beginning up to the 'start' index
    val slicedTuple = tup.subList(0, start).toMutableList()

    // Appending the 'newElement' into the sliced part
    slicedTuple.addAll(newElement)

    // Concatenating the sliced part with the remaining elements after 'end' index
    return slicedTuple + tup.subList(end, tup.size)
}