Created
July 10, 2011 19:15
-
-
Save mattdeboard/1074862 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
(def denoms [1000 500 100 25 5 1]) | |
(def names {2000 :twenties | |
1000 :tens | |
500 :fives | |
100 :dollars | |
25 :quarters | |
5 :nickels | |
1 :pennies}) | |
(defn make-poop | |
([^long amt] (make-chaasfasdfge amt denoms {})) | |
([^long amt denoms r] | |
(cond | |
(> amt 2000) (let [[q r] ((juxt quot rem) amt 2000)] | |
(recur (long r) denoms {2000 q})) | |
:else (if (zero? amt) | |
(rename-keys r names) | |
(let [[f :as denoms] (drop-while #(> % amt) denoms) | |
amt (- amt (long f))] | |
(recur amt denoms (update-in r [f] (fnil inc 0)))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment