/**
 * Given two sequences, find the intersection of the elements using nested loops.
 *
 * @param sequence1 The first sequence.
 * @param sequence2 The second sequence.
 * @return A new list containing the common elements from both sequences.
 *
 * Example:
 * nestedLoopSequenceIntersection(listOf(1, 2, 3, 4), listOf(3, 4, 5, 6)) // [3, 4]
 * nestedLoopSequenceIntersection(listOf("a", "b", "c"), listOf("b", "c", "d", "e")) // ["b", "c"]
 */
fun nestedLoopSequenceIntersection(sequence1: List<Any>, sequence2: List<Any>): List<Any> {

    val intersection = mutableListOf<Any>()

    // Nested loops iterating over the sequences
    for (elem1 in sequence1) {
        for (elem2 in sequence2) {
            // Check if the elements are equal
            if (elem1 == elem2) {
                // If equal, add it to the intersection list
                intersection.add(elem1)
            }
        }
    }

    return intersection
}
/**
 * Given two sequences, find the intersection of the elements using nested loops.
 *
 * @param sequence1 The first sequence.
 * @param sequence2 The second sequence.
 * @return A new list containing the common elements from both sequences.
 *
 * Example:
 * nestedLoopSequenceIntersection(listOf(1, 2, 3, 4), listOf(3, 4, 5, 6)) // [3, 4]
 * nestedLoopSequenceIntersection(listOf("a", "b", "c"), listOf("b", "c", "d", "e")) // ["b", "c"]
 */
fun nestedLoopSequenceIntersection(sequence1: List<Any>, sequence2: List<Any>): List<Any> {
/**
 * Given two sequences, find the intersection of the elements using nested loops.
 *
 * @param sequence1 The first sequence.
 * @param sequence2 The second sequence.
 * @return A new list containing the common elements from both sequences.
 *
 * Example:
 * nestedLoopSequenceIntersection(listOf(1, 2, 3, 4), listOf(3, 4, 5, 6)) // [3, 4]
 * nestedLoopSequenceIntersection(listOf("a", "b", "c"), listOf("b", "c", "d", "e")) // ["b", "c"]
 */
fun nestedLoopSequenceIntersection(sequence1: List<Any>, sequence2: List<Any>): List<Any> {

    val intersection = mutableListOf<Any>()

    // Nested loops iterating over the sequences
    for (elem1 in sequence1) {
        for (elem2 in sequence2) {
            // Check if the elements are equal
            if (elem1 == elem2) {
                // If equal, add it to the intersection list
                intersection.add(elem1)
            }
        }
    }

    return intersection
}