/**
 * Find the intersection of two lists using while loop and list comprehension.
 *
 * @param list1 The first list.
 * @param list2 The second list.
 * @return The intersection of the two lists.
 */
fun intersectWhileListComprehension(list1: List<Any>, list2: List<Any>): List<Any> {

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

    // Iterate through the elements of list1
    var i = 0
    while (i < list1.size) {
        // Iterate through the elements of list2
        var j = 0
        while (j < list2.size) {
            // Check if the current element of list1 is equal to the current element of list2
            if (list1[i] == list2[j]) {
                // Add the common element to the intersect list
                intersect.add(list1[i])
                break  // Break the inner loop if a match is found
            }
            j++
        }
        i++
    }

    // Use list comprehension to remove duplicates from the intersect list
    val distinctIntersect = intersect.distinct()

    return distinctIntersect
}
/**
 * Find the intersection of two lists using while loop and list comprehension.
 *
 * @param list1 The first list.
 * @param list2 The second list.
 * @return The intersection of the two lists.
 */
fun intersectWhileListComprehension(list1: List<Any>, list2: List<Any>): List<Any> {
/**
 * Find the intersection of two lists using while loop and list comprehension.
 *
 * @param list1 The first list.
 * @param list2 The second list.
 * @return The intersection of the two lists.
 */
fun intersectWhileListComprehension(list1: List<Any>, list2: List<Any>): List<Any> {

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

    // Iterate through the elements of list1
    var i = 0
    while (i < list1.size) {
        // Iterate through the elements of list2
        var j = 0
        while (j < list2.size) {
            // Check if the current element of list1 is equal to the current element of list2
            if (list1[i] == list2[j]) {
                // Add the common element to the intersect list
                intersect.add(list1[i])
                break  // Break the inner loop if a match is found
            }
            j++
        }
        i++
    }

    // Use list comprehension to remove duplicates from the intersect list
    val distinctIntersect = intersect.distinct()

    return distinctIntersect
}