/**
 * Given two lists, list1 and list2, finds the common elements between them.
 * This function first compares the elements in list1 as tuples and slices of list2,
 * then returns a list of the common elements found.
 *
 * @param list1 A list of elements.
 * @param list2 A list of elements.
 * @return A list containing the common elements found in both list1 and list2.
 */
fun findCommonElements(list1: List<Any>, list2: List<Any>): List<Any> {

    val commonElements = mutableListOf<Any>()

    // Create tuples from list1 elements
    val list1Tuples = list1.map { listOf(it) }

    // Create slices from list2
    val list2Slices = list2.windowed(size = 2)

    // Compare tuples and slices to find common elements
    for (tuple1 in list1Tuples) {
        for (slice2 in list2Slices) {
            if (tuple1 == slice2) {
                commonElements.add(list1[list1Tuples.indexOf(tuple1)])
            }
        }
    }

    return commonElements
}
/**
 * Given two lists, list1 and list2, finds the common elements between them.
 * This function first compares the elements in list1 as tuples and slices of list2,
 * then returns a list of the common elements found.
 *
 * @param list1 A list of elements.
 * @param list2 A list of elements.
 * @return A list containing the common elements found in both list1 and list2.
 */
fun findCommonElements(list1: List<Any>, list2: List<Any>): List<Any> {
/**
 * Given two lists, list1 and list2, finds the common elements between them.
 * This function first compares the elements in list1 as tuples and slices of list2,
 * then returns a list of the common elements found.
 *
 * @param list1 A list of elements.
 * @param list2 A list of elements.
 * @return A list containing the common elements found in both list1 and list2.
 */
fun findCommonElements(list1: List<Any>, list2: List<Any>): List<Any> {

    val commonElements = mutableListOf<Any>()

    // Create tuples from list1 elements
    val list1Tuples = list1.map { listOf(it) }

    // Create slices from list2
    val list2Slices = list2.windowed(size = 2)

    // Compare tuples and slices to find common elements
    for (tuple1 in list1Tuples) {
        for (slice2 in list2Slices) {
            if (tuple1 == slice2) {
                commonElements.add(list1[list1Tuples.indexOf(tuple1)])
            }
        }
    }

    return commonElements
}