Skip to content

Instantly share code, notes, and snippets.

@katsuyan
Last active March 3, 2017 09:12
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 katsuyan/af4d9dfbd33604e188248f79b23b6cce to your computer and use it in GitHub Desktop.
Save katsuyan/af4d9dfbd33604e188248f79b23b6cce to your computer and use it in GitHub Desktop.
数学パズルonClojure-Q5
(ns puzzule.q5)
(defn exchange-recur [acc money coin-num coins max]
(cond (or (< coin-num 0) (> acc max)) 0
(= money 0) 1
:else (+ (exchange-recur (inc acc)
(- money (get coins coin-num))
coin-num
coins
max)
(exchange-recur acc
money
(dec coin-num)
coins
max))))
(defn exchange [money coins max]
(let [coin-num (- (count coins) 1)]
(exchange-recur 0 money coin-num coins max)))
(def answer (exchange 1000 [10 50 100 500] 15))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment