elm/exercises/nucleotide-count/NucleotideCount.example

50 lines
737 B
Text
Raw Normal View History

module NucleotideCount exposing (..)
2016-03-17 01:36:38 +00:00
import String
2016-04-10 02:48:05 +00:00
version : Int
version =
2
2016-04-10 02:48:05 +00:00
type alias NucleotideCounts =
{ a : Int
, t : Int
, c : Int
, g : Int
}
2016-04-10 02:48:05 +00:00
init : NucleotideCounts
init =
{ a = 0
, t = 0
, c = 0
, g = 0
}
2016-04-10 02:48:05 +00:00
update : Char -> NucleotideCounts -> NucleotideCounts
update char counts =
case char of
'A' ->
{ counts | a = counts.a + 1 }
2016-04-10 02:48:05 +00:00
'T' ->
{ counts | t = counts.t + 1 }
2016-04-10 02:48:05 +00:00
'C' ->
{ counts | c = counts.c + 1 }
2016-04-10 02:48:05 +00:00
'G' ->
{ counts | g = counts.g + 1 }
2016-04-10 02:48:05 +00:00
_ ->
counts
2016-04-10 02:48:05 +00:00
nucleotideCounts : String -> NucleotideCounts
nucleotideCounts sequence =
String.foldl update init sequence