Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
14
Task/Count-the-coins/Clojure/count-the-coins.clj
Normal file
14
Task/Count-the-coins/Clojure/count-the-coins.clj
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
(def denomination-kind [1 5 10 25])
|
||||
|
||||
(defn- cc [amount denominations]
|
||||
(cond (= amount 0) 1
|
||||
(or (< amount 0) (empty? denominations)) 0
|
||||
:else (+ (cc amount (rest denominations))
|
||||
(cc (- amount (first denominations)) denominations))))
|
||||
|
||||
(defn count-change
|
||||
"Calculates the number of times you can give change with the given denominations."
|
||||
[amount denominations]
|
||||
(cc amount denominations))
|
||||
|
||||
(count-change 15 denomination-kind) ; = 6
|
||||
Loading…
Add table
Add a link
Reference in a new issue