/**
 * This function performs operations on sets to simulate a zoo by harnessing the power of the step parameter.
 *
 * @param zoo A set representing the animals in the zoo.
 * @param step An integer representing the step size for set operations.
 * @return A set representing the final result of the set operations.
 */
fun setOperations(zoo: Set<String>, step: Int): Set<String> {

    // Remove every second animal from the zoo
    var zooList = zoo.toList()
    zooList = zooList.filterIndexed { index, _ -> index % step == 0 }

    // Split the remaining zoo into two equal parts
    val half = zooList.size / 2
    val zoo1 = zooList.subList(0, half).toSet()
    val zoo2 = zooList.subList(half, zooList.size).toSet()

    // Union the two parts together
    val unionResult = zoo1.union(zoo2)

    // Take the intersection of the union with itself
    var intersectionResult = unionResult.intersect(unionResult)

    // Remove every third animal from the intersection
    intersectionResult = intersectionResult.filterIndexed { index, _ -> index % step != 0 }.toSet()

    // Add a new animal "Elephant" to the intersection
    intersectionResult = intersectionResult.toMutableSet()
    intersectionResult.add("Elephant")

    // Remove every fourth animal from the intersection
    intersectionResult = intersectionResult.filterIndexed { index, _ -> index % step != 0 }.toSet()

    return intersectionResult
}
/**
 * This function performs operations on sets to simulate a zoo by harnessing the power of the step parameter.
 *
 * @param zoo A set representing the animals in the zoo.
 * @param step An integer representing the step size for set operations.
 * @return A set representing the final result of the set operations.
 */
fun setOperations(zoo: Set<String>, step: Int): Set<String> {
/**
 * This function performs operations on sets to simulate a zoo by harnessing the power of the step parameter.
 *
 * @param zoo A set representing the animals in the zoo.
 * @param step An integer representing the step size for set operations.
 * @return A set representing the final result of the set operations.
 */
fun setOperations(zoo: Set<String>, step: Int): Set<String> {

    // Remove every second animal from the zoo
    var zooList = zoo.toList()
    zooList = zooList.filterIndexed { index, _ -> index % step == 0 }

    // Split the remaining zoo into two equal parts
    val half = zooList.size / 2
    val zoo1 = zooList.subList(0, half).toSet()
    val zoo2 = zooList.subList(half, zooList.size).toSet()

    // Union the two parts together
    val unionResult = zoo1.union(zoo2)

    // Take the intersection of the union with itself
    var intersectionResult = unionResult.intersect(unionResult)

    // Remove every third animal from the intersection
    intersectionResult = intersectionResult.filterIndexed { index, _ -> index % step != 0 }.toSet()

    // Add a new animal "Elephant" to the intersection
    intersectionResult = intersectionResult.toMutableSet()
    intersectionResult.add("Elephant")

    // Remove every fourth animal from the intersection
    intersectionResult = intersectionResult.filterIndexed { index, _ -> index % step != 0 }.toSet()

    return intersectionResult
}