Skip to content

Instantly share code, notes, and snippets.

@rlorca
Created October 1, 2010 16:16
Show Gist options
  • Save rlorca/606423 to your computer and use it in GitHub Desktop.
Save rlorca/606423 to your computer and use it in GitHub Desktop.
Oban numbers
; 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