/**
 * This function returns a list of tuples where each tuple contains elements that are present in all tuples of the given
 * tuple list and satisfy all the conditions specified in the condition list.
 *
 * @param tupleList A list of tuples where each tuple represents a collection of elements.
 * @param conditionList A list of conditions written as strings that should be satisfied by the elements.
 * @return A list of tuples where each tuple contains elements satisfying the conditions and present in all tuples.
 */
fun getCommonElements(tupleList: List<List<Int>>, conditionList: List<String>): List<List<Int>> {

    val commonElements = mutableListOf<List<Int>>()

    // Iterate through each tuple in the tuple list
    for (tup in tupleList) {
        // Check if all conditions are satisfied in the current tuple
        if (conditionList.all { condition -> evalCondition(condition, tup) }) {
            commonElements.add(tup)
        }
    }

    return commonElements
}

fun evalCondition(condition: String, tup: List<Int>): Boolean {
    return when (condition) {
        "tup[0] >= 4" -> tup[0] >= 4
        "tup[2] % 2 == 1" -> tup[2] % 2 == 1
        else -> false
    }
}

// Example usage
val tupleList = listOf(listOf(1, 2, 3), listOf(4, 5, 6), listOf(7, 8, 9))
val conditionList = listOf("tup[0] >= 4", "tup[2] % 2 == 1")
/**
 * This function returns a list of tuples where each tuple contains elements that are present in all tuples of the given
 * tuple list and satisfy all the conditions specified in the condition list.
 *
 * @param tupleList A list of tuples where each tuple represents a collection of elements.
 * @param conditionList A list of conditions written as strings that should be satisfied by the elements.
 * @return A list of tuples where each tuple contains elements satisfying the conditions and present in all tuples.
 */
fun getCommonElements(tupleList: List<List<Int>>, conditionList: List<String>): List<List<Int>> {
/**
 * This function returns a list of tuples where each tuple contains elements that are present in all tuples of the given
 * tuple list and satisfy all the conditions specified in the condition list.
 *
 * @param tupleList A list of tuples where each tuple represents a collection of elements.
 * @param conditionList A list of conditions written as strings that should be satisfied by the elements.
 * @return A list of tuples where each tuple contains elements satisfying the conditions and present in all tuples.
 */
fun getCommonElements(tupleList: List<List<Int>>, conditionList: List<String>): List<List<Int>> {

    val commonElements = mutableListOf<List<Int>>()

    // Iterate through each tuple in the tuple list
    for (tup in tupleList) {
        // Check if all conditions are satisfied in the current tuple
        if (conditionList.all { condition -> evalCondition(condition, tup) }) {
            commonElements.add(tup)
        }
    }

    return commonElements
}

fun evalCondition(condition: String, tup: List<Int>): Boolean {
    return when (condition) {
        "tup[0] >= 4" -> tup[0] >= 4
        "tup[2] % 2 == 1" -> tup[2] % 2 == 1
        else -> false
    }
}

// Example usage
val tupleList = listOf(listOf(1, 2, 3), listOf(4, 5, 6), listOf(7, 8, 9))
val conditionList = listOf("tup[0] >= 4", "tup[2] % 2 == 1")