Created
September 2, 2015 21:48
-
-
Save aprobus/100e26e5ca894bb6590f to your computer and use it in GitHub Desktop.
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
(defn change-coins | |
"Takes in input n as the amount in cents. | |
Returns the map of coins and their counts." | |
[n] | |
(loop [n n | |
coins [100 25 10 5 1] | |
purse {}] | |
(if (empty? coins) | |
purse | |
(let [coin (first coins) | |
num-coin (quot n coin) | |
remainder (rem n coin)] | |
(recur remainder (rest coins) (assoc purse coin num-coin)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment