Created
February 12, 2010 06:34
-
-
Save nathell/302375 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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