Skip to content

Instantly share code, notes, and snippets.

@trikitrok
Created June 29, 2014 09:53
Show Gist options
  • Save trikitrok/e70d659c53990a7ead20 to your computer and use it in GitHub Desktop.
Save trikitrok/e70d659c53990a7ead20 to your computer and use it in GitHub Desktop.
(ns dna)
(def dna-nucleotides #{\A, \T, \C, \G})
(def nucleotides (conj dna-nucleotides \U))
(defn nucleotide-counts [strand]
(let
[counted-nucleotides
(zipmap dna-nucleotides (repeat (count dna-nucleotides) 0))
count
(fn [counted-nucleotides nucleotide]
(assoc
counted-nucleotides
nucleotide
(+ (get counted-nucleotides nucleotide) 1)))]
(reduce count counted-nucleotides strand)))
(defn count [nucleotide strand]
(if (contains? nucleotides nucleotide)
(get (nucleotide-counts strand) nucleotide 0)
(throw (Exception. "invalid nucleotide"))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment