michelchenrich

coin-changer

Jan 27th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (defn make-change [amount]
  2.     (loop [coins [100 50 25 10 5 1], change [], amount amount]
  3.         (if (empty? coins)
  4.             change
  5.             (let [coin (first coins)]
  6.                 (if (< amount coin)
  7.                     (recur (rest coins) change amount)
  8.                     (recur coins (conj change coin) (- amount coin)))))))
Advertisement
Add Comment
Please, Sign In to add comment