/**
 * This function performs nested set operations using logical operators.
 *
 * @param set1 The first set.
 * @param set2 The second set.
 * @param operator The logical operator to be used. Valid operators are "and", "or", and "not".
 * @return Result of the nested set operation.
 * @throws IllegalArgumentException If the operator provided is not valid.
 */
fun nestedSetOperation(set1: Set<Int>, set2: Set<Int>, operator: String): Set<Int> {

    return when (operator) {
        "and" -> set1.intersect(set2)
        "or" -> set1.union(set2)
        "not" -> set1.subtract(set2)
        else -> throw IllegalArgumentException("Invalid operator provided. Valid operators are 'and', 'or', and 'not'.")
    }
}

// Exercise
/**
 * This function performs nested set operations using logical operators.
 *
 * @param set1 The first set.
 * @param set2 The second set.
 * @param operator The logical operator to be used. Valid operators are "and", "or", and "not".
 * @return Result of the nested set operation.
 * @throws IllegalArgumentException If the operator provided is not valid.
 */
fun nestedSetOperation(set1: Set<Int>, set2: Set<Int>, operator: String): Set<Int> {
/**
 * This function performs nested set operations using logical operators.
 *
 * @param set1 The first set.
 * @param set2 The second set.
 * @param operator The logical operator to be used. Valid operators are "and", "or", and "not".
 * @return Result of the nested set operation.
 * @throws IllegalArgumentException If the operator provided is not valid.
 */
fun nestedSetOperation(set1: Set<Int>, set2: Set<Int>, operator: String): Set<Int> {

    return when (operator) {
        "and" -> set1.intersect(set2)
        "or" -> set1.union(set2)
        "not" -> set1.subtract(set2)
        else -> throw IllegalArgumentException("Invalid operator provided. Valid operators are 'and', 'or', and 'not'.")
    }
}

// Exercise