Sha256: 9bf6d90b259c286e1855bf98f1010d2c0dbb52ce6fbc6e9995832f9ff1775620

Contents?: true

Size: 624 Bytes

Versions: 270

Compression:

Stored size: 624 Bytes

Contents

class DNA(strand: String) {
    init {
        require(strand.matches(Regex("^[$nucleotides]*$")), { "DNA sequence contains invalid nucleotides sequence." })
    }

    companion object DNA {
        val nucleotides = "ATCG"
        val emptyNucleotideCounts = nucleotides.map { it to 0 }.toMap()
    }

    val nucleotideCounts: Map<Char, Int> by lazy {
        emptyNucleotideCounts + strand.groupBy { it }.mapValues { it.value.size }
    }

    fun count(nucleotide: Char): Int {
        require(nucleotide in nucleotides, { "$nucleotide is not a nucleotide" })

        return nucleotideCounts[nucleotide] ?: 0
    }
}

Version data entries

270 entries across 270 versions & 1 rubygems

Version Path
trackler-2.2.1.52 tracks/kotlin/exercises/nucleotide-count/.meta/src/reference/kotlin/DNA.kt
trackler-2.2.1.51 tracks/kotlin/exercises/nucleotide-count/.meta/src/reference/kotlin/DNA.kt
trackler-2.2.1.50 tracks/kotlin/exercises/nucleotide-count/.meta/src/reference/kotlin/DNA.kt
trackler-2.2.1.49 tracks/kotlin/exercises/nucleotide-count/.meta/src/reference/kotlin/DNA.kt
trackler-2.2.1.48 tracks/kotlin/exercises/nucleotide-count/.meta/src/reference/kotlin/DNA.kt
trackler-2.2.1.47 tracks/kotlin/exercises/nucleotide-count/.meta/src/reference/kotlin/DNA.kt
trackler-2.2.1.46 tracks/kotlin/exercises/nucleotide-count/.meta/src/reference/kotlin/DNA.kt
trackler-2.2.1.45 tracks/kotlin/exercises/nucleotide-count/.meta/src/reference/kotlin/DNA.kt
trackler-2.2.1.44 tracks/kotlin/exercises/nucleotide-count/.meta/src/reference/kotlin/DNA.kt
trackler-2.2.1.43 tracks/kotlin/exercises/nucleotide-count/.meta/src/reference/kotlin/DNA.kt
trackler-2.2.1.42 tracks/kotlin/exercises/nucleotide-count/.meta/src/reference/kotlin/DNA.kt
trackler-2.2.1.41 tracks/kotlin/exercises/nucleotide-count/.meta/src/reference/kotlin/DNA.kt
trackler-2.2.1.40 tracks/kotlin/exercises/nucleotide-count/.meta/src/reference/kotlin/DNA.kt
trackler-2.2.1.39 tracks/kotlin/exercises/nucleotide-count/.meta/src/reference/kotlin/DNA.kt
trackler-2.2.1.38 tracks/kotlin/exercises/nucleotide-count/.meta/src/reference/kotlin/DNA.kt
trackler-2.2.1.37 tracks/kotlin/exercises/nucleotide-count/.meta/src/reference/kotlin/DNA.kt
trackler-2.2.1.36 tracks/kotlin/exercises/nucleotide-count/.meta/src/reference/kotlin/DNA.kt
trackler-2.2.1.35 tracks/kotlin/exercises/nucleotide-count/.meta/src/reference/kotlin/DNA.kt
trackler-2.2.1.34 tracks/kotlin/exercises/nucleotide-count/.meta/src/reference/kotlin/DNA.kt
trackler-2.2.1.33 tracks/kotlin/exercises/nucleotide-count/.meta/src/reference/kotlin/DNA.kt