/**
 * This function computes the intersection of two nested lists.
 *
 * @param list1 a nested list containing geological data
 * @param list2 another nested list containing geological data
 * @return intersectedList a new list containing elements present in both list1 and list2
 */
fun intersectLists(list1: List<List<String>>, list2: List<List<String>>): List<String> {

    val intersectedList = mutableListOf<String>()

    // Iterate over each sublist in list1
    for (sublist1 in list1) {
        // Iterate over each sublist in list2
        for (sublist2 in list2) {
            // Iterate over each element in sublist1
            for (element1 in sublist1) {
                // Iterate over each element in sublist2
                for (element2 in sublist2) {
                    // Check if the elements are equal
                    if (element1 == element2) {
                        // Append the element to the intersected list
                        intersectedList.add(element1)
                    }
                }
            }
        }
    }

    return intersectedList
}

// Example usage
val list1 = listOf(listOf("rock", "mineral", "sediment"), listOf("fossil", "igneous"), listOf("mineral"))
val list2 = listOf(listOf("mineral", "rock"), listOf("fossil"), listOf("sediment", "igneous"))

val result = intersectLists(list1, list2)
/**
 * This function computes the intersection of two nested lists.
 *
 * @param list1 a nested list containing geological data
 * @param list2 another nested list containing geological data
 * @return intersectedList a new list containing elements present in both list1 and list2
 */
fun intersectLists(list1: List<List<String>>, list2: List<List<String>>): List<String> {
/**
 * This function computes the intersection of two nested lists.
 *
 * @param list1 a nested list containing geological data
 * @param list2 another nested list containing geological data
 * @return intersectedList a new list containing elements present in both list1 and list2
 */
fun intersectLists(list1: List<List<String>>, list2: List<List<String>>): List<String> {

    val intersectedList = mutableListOf<String>()

    // Iterate over each sublist in list1
    for (sublist1 in list1) {
        // Iterate over each sublist in list2
        for (sublist2 in list2) {
            // Iterate over each element in sublist1
            for (element1 in sublist1) {
                // Iterate over each element in sublist2
                for (element2 in sublist2) {
                    // Check if the elements are equal
                    if (element1 == element2) {
                        // Append the element to the intersected list
                        intersectedList.add(element1)
                    }
                }
            }
        }
    }

    return intersectedList
}

// Example usage
val list1 = listOf(listOf("rock", "mineral", "sediment"), listOf("fossil", "igneous"), listOf("mineral"))
val list2 = listOf(listOf("mineral", "rock"), listOf("fossil"), listOf("sediment", "igneous"))

val result = intersectLists(list1, list2)