scheme-playground/money-exchange.scm

15 lines
437 B
Scheme

(define (change amount kinds-of-coins)
(cond ((or (< amount 0) (= kinds-of-coins 0)) 0)
((= amount 0) 1)
(else (+ (change amount (- kinds-of-coins 1))
(change (- amount (amount-wo-largest-coin kinds-of-coins)) kinds-of-coins)))))
(define (amount-wo-largest-coin coins-left)
(cond ((= coins-left 5) 50)
((= coins-left 4) 25)
((= coins-left 3) 10)
((= coins-left 2) 5)
((= coins-left 1) 1)))
(print (change 100 5))