Created
October 1, 2010 16:16
-
-
Save rlorca/606423 to your computer and use it in GitHub Desktop.
Oban numbers
This file contains hidden or 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
; from http://programmingpraxis.com/2010/10/01/oban-numbers/ | |
(ns oban) | |
(def base [nil nil "three" nil "five" "six" "seven" "eight" "nine"]) | |
(def dec ["twenty" "thirty" "fifty" nil "sixty" "seventy" "eigthy" "ninety"]) | |
(def teens ["ten" "eleven" "twelve" "thirteen" "fourteen" "fifteen" "sixteen" "seventeen" "eighteen" "nineteen"]) | |
(declare combine comb) | |
(defn gen-seq [] | |
(let [nums (concat base teens (combine dec base))] | |
(concat nums (combine base ["hundred"] nums)))) | |
(defn combine [& colls] | |
(reduce comb colls)) | |
(defn comb [head tail] | |
(for [h head t tail] | |
(if (or (nil? t) (nil? h)) | |
nil | |
(str h " " t)))) | |
(time | |
(doall | |
(for [word (gen-seq) :when word] | |
(print word "\n")))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment