SICP 2.18 2.19 代码
2.18 要求反转参数表
2.19 要求写出兑换零钱方式计数程序,并且零钱种类可变
#lang planet neil/sicp
;;2.18
(define (reverse input-list)
(if (null? (cdr input-list))
input-list
(append (reverse (cdr input-list)) (cons (car input-list) '()))))
;;2.19
(define no-more? null?)
(define first-denomination car)
(define except-first-denomination cdr)
(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))
;;test
(reverse (list 1 2 3 4 5))
(cc 100 us-coins)