You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
642 B
21 lines
642 B
(define (cc amount kinds-of-coins) |
|
(cond ((= amount 0) 1) |
|
((or (< amount 0) (= kinds-of-coins 0)) 0) |
|
(else (+ (cc amount |
|
(- kinds-of-coins 1)) |
|
(cc (- amount |
|
(first-denomination |
|
kinds-of-coins)) |
|
kinds-of-coins))))) |
|
|
|
(define (count-change amount) (cc amount 5)) |
|
|
|
(define (first-denomination kinds-of-coins) |
|
(cond ((= kinds-of-coins 1) 1) |
|
((= kinds-of-coins 2) 5) |
|
((= kinds-of-coins 3) 10) |
|
((= kinds-of-coins 4) 25) |
|
((= kinds-of-coins 5) 50))) |
|
|
|
(display (count-change 100)) |
|
(newline)
|
|
|