Last active
August 29, 2015 14:06
-
-
Save onemouth/c22aa764a61709f641f1 to your computer and use it in GitHub Desktop.
Exchange Money
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
(defn exchange [table coin] | |
(let [table-size (count table)] | |
(reduce #(assoc %1 %2 (+ (nth %1 %2) (nth %1 (- %2 coin)))) | |
table | |
(range coin table-size)))) | |
(defn total-exchange [money coins] | |
(let [table (->> (take money (repeat 0N)) | |
(#(conj % 1N)) | |
vec)] | |
(reduce #(exchange %1 %2) table coins))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment