Skip to content

Instantly share code, notes, and snippets.

@aprobus
Created September 2, 2015 21:48
Show Gist options
  • Save aprobus/100e26e5ca894bb6590f to your computer and use it in GitHub Desktop.
Save aprobus/100e26e5ca894bb6590f to your computer and use it in GitHub Desktop.
(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