learning F#, it seems pretty cool, favourite functional language so far.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

NucleotideCount.fs 797B

1234567891011121314151617181920212223242526
  1. module NucleotideCount
  2. let isValidNucleotide nucleotide =
  3. nucleotide = 'A'
  4. || nucleotide = 'C'
  5. || nucleotide = 'G'
  6. || nucleotide = 'T'
  7. let validInput (strand: string) =
  8. String.collect (fun c -> if isValidNucleotide c then string (c) else "") strand = strand
  9. let nucleotideCounts (strand: string): Option<Map<char, int>> =
  10. if validInput strand then
  11. let mutable counts =
  12. Map.empty.Add('A', 0).Add('C', 0).Add('G', 0).Add('T', 0)
  13. Seq.iter (fun c ->
  14. if counts.ContainsKey c then
  15. let current = counts.Item c
  16. counts <- counts.Remove(c)
  17. counts <- counts.Add(c, current + 1)
  18. else
  19. counts <- counts.Add(c, 1)) strand
  20. Some(counts)
  21. else
  22. None