Skip to content

Instantly share code, notes, and snippets.

@nathell
Created February 12, 2010 06:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathell/302375 to your computer and use it in GitHub Desktop.
Save nathell/302375 to your computer and use it in GitHub Desktop.
(defn read-text []
(take-while (comp not empty?) (repeatedly read-line)))
(defn char<= [x y z]
(and (>= 0 (compare x y)) (>= 0 (compare y z))))
(defn update-map [m letter]
(let [letter (Character/toUpperCase letter)]
(if (char<= \A letter \Z)
(assoc m letter (inc (get m letter 0)))
m)))
(defn stats [text]
(reduce update-map {} (apply concat text)))
(defn display-stats [stats]
(dorun (map (fn [[k v]] (printf "%s: %2d %s\n" k v (apply str (repeat v (char 177)))))
(sort-by key stats))))
(display-stats (stats (read-text)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment