/**
 * This function takes in two sets of genes and a gene to be repeated. It returns a list of genes that are common
 * between the two sets and are repeated the same number of times as the repeated_gene.
 *
 * @param geneSet1 A set of genes.
 * @param geneSet2 Another set of genes.
 * @param repeatedGene A gene to be repeated.
 * @return A list of common genes that are repeated the same number of times as the repeatedGene.
 */
fun findCommonGenes(geneSet1: Set<String>?, geneSet2: Set<String>?, repeatedGene: String?): List<String> {

    val commonGenes = mutableListOf<String>()

    // Check if any of the sets is empty
    if (geneSet1 == null || geneSet2 == null) {
        return commonGenes
    }

    // Concatenate the two sets and convert them into a list
    val allGenes = geneSet1.toList() + geneSet2.toList()

    // Check if the repeatedGene is not null
    if (repeatedGene == null) {
        return commonGenes
    }

    // Repeat the gene as many times as its occurrence in allGenes
    val repeatedGenes = List(allGenes.count { it == repeatedGene }) { repeatedGene }

    return repeatedGenes
}
/**
 * This function takes in two sets of genes and a gene to be repeated. It returns a list of genes that are common
 * between the two sets and are repeated the same number of times as the repeated_gene.
 *
 * @param geneSet1 A set of genes.
 * @param geneSet2 Another set of genes.
 * @param repeatedGene A gene to be repeated.
 * @return A list of common genes that are repeated the same number of times as the repeatedGene.
 */
fun findCommonGenes(geneSet1: Set<String>?, geneSet2: Set<String>?, repeatedGene: String?): List<String> {
/**
 * This function takes in two sets of genes and a gene to be repeated. It returns a list of genes that are common
 * between the two sets and are repeated the same number of times as the repeated_gene.
 *
 * @param geneSet1 A set of genes.
 * @param geneSet2 Another set of genes.
 * @param repeatedGene A gene to be repeated.
 * @return A list of common genes that are repeated the same number of times as the repeatedGene.
 */
fun findCommonGenes(geneSet1: Set<String>?, geneSet2: Set<String>?, repeatedGene: String?): List<String> {

    val commonGenes = mutableListOf<String>()

    // Check if any of the sets is empty
    if (geneSet1 == null || geneSet2 == null) {
        return commonGenes
    }

    // Concatenate the two sets and convert them into a list
    val allGenes = geneSet1.toList() + geneSet2.toList()

    // Check if the repeatedGene is not null
    if (repeatedGene == null) {
        return commonGenes
    }

    // Repeat the gene as many times as its occurrence in allGenes
    val repeatedGenes = List(allGenes.count { it == repeatedGene }) { repeatedGene }

    return repeatedGenes
}