/**
 * Given a list of rock layers and a list of minerals, find the common elements between them.
 *
 * @param rockLayers A list of rock layers.
 * @param minerals A list of minerals.
 * @return A list of common elements between rock layers and minerals.
 */
fun findCommonElements(rockLayers: List<String>, minerals: List<String>): List<String> {

    val commonElements = mutableListOf<String>()

    // Loop through each rock layer
    for (layer in rockLayers) {
        // Loop through each mineral
        for (mineral in minerals) {
            // Check if the current mineral is also present in the rock layer
            if (layer.contains(mineral)) {
                // Check if the common element is not already added to the commonElements list
                if (mineral !in commonElements) {
                    // Add the common element to the commonElements list
                    commonElements.add(mineral)
                }
            }
        }
    }

    return commonElements
}

val rockLayers = listOf(
    "Sedimentary rock containing quartz and feldspar",
    "Igneous rock consisting of basalt and granite",
    "Metamorphic rock composed of mica and schist"
)
val minerals = listOf("quartz", "feldspar", "basalt", "schist", "mica")

val commonElements = findCommonElements(rockLayers, minerals)
/**
 * Given a list of rock layers and a list of minerals, find the common elements between them.
 *
 * @param rockLayers A list of rock layers.
 * @param minerals A list of minerals.
 * @return A list of common elements between rock layers and minerals.
 */
fun findCommonElements(rockLayers: List<String>, minerals: List<String>): List<String> {
/**
 * Given a list of rock layers and a list of minerals, find the common elements between them.
 *
 * @param rockLayers A list of rock layers.
 * @param minerals A list of minerals.
 * @return A list of common elements between rock layers and minerals.
 */
fun findCommonElements(rockLayers: List<String>, minerals: List<String>): List<String> {

    val commonElements = mutableListOf<String>()

    // Loop through each rock layer
    for (layer in rockLayers) {
        // Loop through each mineral
        for (mineral in minerals) {
            // Check if the current mineral is also present in the rock layer
            if (layer.contains(mineral)) {
                // Check if the common element is not already added to the commonElements list
                if (mineral !in commonElements) {
                    // Add the common element to the commonElements list
                    commonElements.add(mineral)
                }
            }
        }
    }

    return commonElements
}

val rockLayers = listOf(
    "Sedimentary rock containing quartz and feldspar",
    "Igneous rock consisting of basalt and granite",
    "Metamorphic rock composed of mica and schist"
)
val minerals = listOf("quartz", "feldspar", "basalt", "schist", "mica")

val commonElements = findCommonElements(rockLayers, minerals)