-
-
Save amalloy/1074857 to your computer and use it in GitHub Desktop.
change.clj
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
(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-chaasfasdfge | |
([^long amt] (make-change 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