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