class DNA(val nucleotides: String) {
    val nucleotideCounts: MutableMap<Char, Int> = createNucleotideMap()

    fun count(testChar: Char): Int{
        validateNucleotide(testChar)
        return nucleotideCounts.getOrDefault(testChar, 0)
    }

    private fun createNucleotideMap(): MutableMap<Char, Int>{
        nucleotides.onEach { validateNucleotide(it) }
        var tempMap: MutableMap<Char, Int> = emptyMap<Char, Int>().toMutableMap()
        tempMap.put('A', 0)
        tempMap.put('C', 0)
        tempMap.put('G', 0)
        tempMap.put('T', 0)
        for (i in tempMap){
            tempMap.put(i.key, nucleotides.count { it == i.key })
        }
        return tempMap
    }

    private fun validateNucleotide(testChar: Char){
        if (testChar != 'A'){
            if (testChar != 'C'){
                if (testChar != 'G'){
                    if (testChar != 'T')
                        throw IllegalArgumentException()
                }
            }
        }
    }
}
