/**
 * Given two lists, return a new list containing the elements that appear in both lists.
 *
 * @param list1 The first list.
 * @param list2 The second list.
 * @return A new list containing the common elements.
 *
 * Example:
 * compareLists(listOf(1, 2, 3, 4), listOf(3, 4, 5, 6)) -> listOf(3, 4)
 *
 * Required knowledge: booleans, identity comparison, list iteration.
 */
fun compareLists(list1: List<Int>, list2: List<Int>): List<Int> {

    // Initialize an empty list to store the common elements
    val commonElements = mutableListOf<Int>()

    // Loop through the first list
    for (element in list1) {
        // Check if the element is also present in the second list using identity comparison
        if (element in list2 && element !in commonElements) {
            // Append the common element to the list
            commonElements.add(element)
        }
    }

    return commonElements
}
/**
 * Given two lists, return a new list containing the elements that appear in both lists.
 *
 * @param list1 The first list.
 * @param list2 The second list.
 * @return A new list containing the common elements.
 *
 * Example:
 * compareLists(listOf(1, 2, 3, 4), listOf(3, 4, 5, 6)) -> listOf(3, 4)
 *
 * Required knowledge: booleans, identity comparison, list iteration.
 */
fun compareLists(list1: List<Int>, list2: List<Int>): List<Int> {
/**
 * Given two lists, return a new list containing the elements that appear in both lists.
 *
 * @param list1 The first list.
 * @param list2 The second list.
 * @return A new list containing the common elements.
 *
 * Example:
 * compareLists(listOf(1, 2, 3, 4), listOf(3, 4, 5, 6)) -> listOf(3, 4)
 *
 * Required knowledge: booleans, identity comparison, list iteration.
 */
fun compareLists(list1: List<Int>, list2: List<Int>): List<Int> {

    // Initialize an empty list to store the common elements
    val commonElements = mutableListOf<Int>()

    // Loop through the first list
    for (element in list1) {
        // Check if the element is also present in the second list using identity comparison
        if (element in list2 && element !in commonElements) {
            // Append the common element to the list
            commonElements.add(element)
        }
    }

    return commonElements
}