/**
 * Given a range and a list, this function copies a sublist within the specified range and iterates over it.
 *
 * @param start The starting index of the range.
 * @param end The ending index of the range.
 * @param originalList The original list from which the sublist is copied.
 * @return The copied sublist.
 * @throws IllegalArgumentException If the start or end index is out of range.
 */
fun copyAndIterate(start: Int, end: Int, originalList: List<Int>): List<Int> {

    if (start < 0 || end >= originalList.size) {
        throw IllegalArgumentException("Invalid start or end index")
    }

    // Copying the sublist from the original list
    val copiedList = originalList.subList(start, end + 1)

    // Iterating over the copied sublist
    for (item in copiedList) {
        // Perform complex engineering calculations here
        println(item)
    }

    return copiedList
}
/**
 * Given a range and a list, this function copies a sublist within the specified range and iterates over it.
 *
 * @param start The starting index of the range.
 * @param end The ending index of the range.
 * @param originalList The original list from which the sublist is copied.
 * @return The copied sublist.
 * @throws IllegalArgumentException If the start or end index is out of range.
 */
fun copyAndIterate(start: Int, end: Int, originalList: List<Int>): List<Int> {
/**
 * Given a range and a list, this function copies a sublist within the specified range and iterates over it.
 *
 * @param start The starting index of the range.
 * @param end The ending index of the range.
 * @param originalList The original list from which the sublist is copied.
 * @return The copied sublist.
 * @throws IllegalArgumentException If the start or end index is out of range.
 */
fun copyAndIterate(start: Int, end: Int, originalList: List<Int>): List<Int> {

    if (start < 0 || end >= originalList.size) {
        throw IllegalArgumentException("Invalid start or end index")
    }

    // Copying the sublist from the original list
    val copiedList = originalList.subList(start, end + 1)

    // Iterating over the copied sublist
    for (item in copiedList) {
        // Perform complex engineering calculations here
        println(item)
    }

    return copiedList
}