Solve nucleotide count in Scala