Last active
March 3, 2017 09:12
-
-
Save katsuyan/af4d9dfbd33604e188248f79b23b6cce to your computer and use it in GitHub Desktop.
数学パズルonClojure-Q5
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 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