/**
 * This function takes in a DNA sequence and searches for a specific gene.
 * The gene starts with the sequence 'ATG' and ends with any of the stop codons: 'TAA', 'TAG', or 'TGA'.
 * It returns the index where the gene starts if found, and -1 otherwise.
 */
fun findGene(sequence: String): Int {

    val startCodon = "ATG"
    val stopCodons = listOf("TAA", "TAG", "TGA")

    for (i in sequence.indices) {
        if (sequence.substring(i, i + 3) == startCodon) {  // Check if current triplet is the start codon
            for (j in (i + 3) until sequence.length step 3) {  // Search for stop codons after start codon
                if (sequence.substring(j, j + 3) in stopCodons) {  // Check if current triplet is a stop codon
                    return i  // Return index where gene starts
                }
            }
            break  // Gene was found, exit both loops
        }
    }
    return -1  // Gene not found
}

// Example usage:
val dnaSequence = "ATGAGCTAAACGTGCTAGGCTGA"
val geneStart = findGene(dnaSequence)
/**
 * This function takes in a DNA sequence and searches for a specific gene.
 * The gene starts with the sequence 'ATG' and ends with any of the stop codons: 'TAA', 'TAG', or 'TGA'.
 * It returns the index where the gene starts if found, and -1 otherwise.
 */
fun findGene(sequence: String): Int {
/**
 * This function takes in a DNA sequence and searches for a specific gene.
 * The gene starts with the sequence 'ATG' and ends with any of the stop codons: 'TAA', 'TAG', or 'TGA'.
 * It returns the index where the gene starts if found, and -1 otherwise.
 */
fun findGene(sequence: String): Int {

    val startCodon = "ATG"
    val stopCodons = listOf("TAA", "TAG", "TGA")

    for (i in sequence.indices) {
        if (sequence.substring(i, i + 3) == startCodon) {  // Check if current triplet is the start codon
            for (j in (i + 3) until sequence.length step 3) {  // Search for stop codons after start codon
                if (sequence.substring(j, j + 3) in stopCodons) {  // Check if current triplet is a stop codon
                    return i  // Return index where gene starts
                }
            }
            break  // Gene was found, exit both loops
        }
    }
    return -1  // Gene not found
}

// Example usage:
val dnaSequence = "ATGAGCTAAACGTGCTAGGCTGA"
val geneStart = findGene(dnaSequence)