Skip to content

Instantly share code, notes, and snippets.

@onemouth
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save onemouth/c22aa764a61709f641f1 to your computer and use it in GitHub Desktop.
Save onemouth/c22aa764a61709f641f1 to your computer and use it in GitHub Desktop.
Exchange Money
(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