Created
April 8, 2016 18:44
-
-
Save becca-bailey/549c67efd0ea5f692031cad2546aa5de 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-speclj.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