2.19 Exercise 2.19
first-denomination, except-first-denomination, and no-more? are all primitive
operations on lists:
(define (first-denomination coin-values) | (car coin-values)) |
|
(define (except-first-denomination coin-values) | (cdr coin-values)) |
|
(define (no-more? coin-values) | (null? coin-values)) |
|
The order of the list coin-values does not affect the answer of cc:
(define (cc amount coin-values) | (cond ((= amount 0) 1) | ((or (< amount 0) (no-more? coin-values)) 0) | (else | (+ (cc amount | (except-first-denomination coin-values)) | (cc (- amount | (first-denomination coin-values)) | coin-values))))) |
|
> (define us-coins (list 50 25 10 5 1)) |
> (= (cc 100 us-coins) (cc 100 (reverse us-coins))) |
#t |