Last active
April 8, 2016 18:48
-
-
Save becca-bailey/d3b57d26f2ea40a5f045631e1b5385df to your computer and use it in GitHub Desktop.
File setup in Clojure
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
(ns coin-changer.core) | |
(def coins [25 10 5 1]) | |
(defn find-max-coin [cents] | |
(loop [possible-coins coins] | |
(if (>= cents (first possible-coins)) | |
(first possible-coins) | |
(recur (rest possible-coins))))) | |
(defn make-change [cents] | |
(loop [cents cents | |
change []] | |
(if (= cents 0) | |
change | |
(let [coin (find-max-coin cents)] | |
(recur (- cents coin) (conj change coin)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment