/**
 * This function finds the intersection of a list and tuples, and returns a new list containing common elements.
 *
 * @param tuplesList A list of tuples.
 * @param listElements A list of elements.
 * @return A new list containing common elements.
 *
 * Example:
 * '``
 * val tuplesList = listOf(listOf(1, 2, 3), listOf(4, 5, 6), listOf(7, 8, 9))
 * val listElements = listOf(2, 5, 8)
 * intersectionOfTuplesAndList(tuplesList, listElements) // [2, 5, 8]
 * '``
 */
fun intersectionOfTuplesAndList(tuplesList: List<List<Int>>, listElements: List<Int>): List<Int> {

    val commonElements = mutableListOf<Int>()

    for (tup in tuplesList) {
        for (element in tup) {
            if (element in listElements && element !in commonElements) {
                commonElements.add(element)
            }
        }
    }

    return commonElements
}
/**
 * This function finds the intersection of a list and tuples, and returns a new list containing common elements.
 *
 * @param tuplesList A list of tuples.
 * @param listElements A list of elements.
 * @return A new list containing common elements.
 *
 * Example:
 * '``
 * val tuplesList = listOf(listOf(1, 2, 3), listOf(4, 5, 6), listOf(7, 8, 9))
 * val listElements = listOf(2, 5, 8)
 * intersectionOfTuplesAndList(tuplesList, listElements) // [2, 5, 8]
 * '``
 */
fun intersectionOfTuplesAndList(tuplesList: List<List<Int>>, listElements: List<Int>): List<Int> {
/**
 * This function finds the intersection of a list and tuples, and returns a new list containing common elements.
 *
 * @param tuplesList A list of tuples.
 * @param listElements A list of elements.
 * @return A new list containing common elements.
 *
 * Example:
 * '``
 * val tuplesList = listOf(listOf(1, 2, 3), listOf(4, 5, 6), listOf(7, 8, 9))
 * val listElements = listOf(2, 5, 8)
 * intersectionOfTuplesAndList(tuplesList, listElements) // [2, 5, 8]
 * '``
 */
fun intersectionOfTuplesAndList(tuplesList: List<List<Int>>, listElements: List<Int>): List<Int> {

    val commonElements = mutableListOf<Int>()

    for (tup in tuplesList) {
        for (element in tup) {
            if (element in listElements && element !in commonElements) {
                commonElements.add(element)
            }
        }
    }

    return commonElements
}