SICP的一些练习题

1.3 较大两个数之和

 (define (MaxSum x y z)
(+ (cond ((or (> x y) (> x z)) x)
(else ))
(cond ((or (> y x) (> y z)) y)
(else ))
(cond ((or (> z x) (> z y)) z)
(else ))))
(MaxSum )

较大两个数之和

牛顿迭代

 (define (Abs x)
(cond ((> x ) x)
((= x ) )
((< x ) (- x))))
(define (Square x) (* x x))
(define (Average x y)
(/ (+ x y) ))
(define (Improve guess x)
(Average guess (/ x guess)))
(define (GoodEnough? guess x)
(< (Abs (- (Square guess) x)) 0.001))
(define (SqrtIter guess x)
(if (GoodEnough? guess x)
guess
(SqrtIter (Improve guess x)
x)))
(SqrtIter )

牛顿迭代

一个表的最后一个表

 (define (last-pair lst)
(if (<= (length lst) )
lst
(last-pair (cdr lst))))

最后一个表

集合操作

 (define (element-of-set? x set)
(cond ((null? set) false)
((equal? x (car set)) true)
(else (element-of-set? x (cdr set))))) (define (adjoin-set x set)
(if (element-of-set? x set)
set
(cons x set))) (define (intersection-set set1 set2)
(cond ((or (null? set1) (null? set2)) '())
((element-of-set? (car set1) set2)
(cons (car set1)
(intersection-set (cdr set1) set2)))
(else (intersection-set (cdr set1) set2)))) (define (union-set set1 set2)
(cond ((null? set1) set2)
((null? set2) set1)
((element-of-set? (car set1) set2)
(union-set (cdr set1) set2))
(else (cons (car set1) (union-set (cdr set1) set2))))) (define set1 (list ))
(define set2 (list ))
(element-of-set? set1)
(element-of-set? set1)
(intersection-set set1 set2)
(union-set set1 set2)

集合

上一篇:What is Zeebe?


下一篇:【8.28校内测试】【区间DP】