日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

sicp第一章部分习题解答

發(fā)布時間:2024/4/11 编程问答 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 sicp第一章部分习题解答 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
(begin(load "util.scm");ex 1.16 計算b的冪 (define (_expt product b n maxn)(if (= n maxn) product(if (<= (* n n) maxn) (_expt (* product product) b (+ n n) maxn)(_expt (* product b) b (+ n 1) maxn))))(define (fast-expt b n)(if (<= n 0) 1(_expt b b 1 n)));ex 1.11 (define (ex1-f n)(cond ((< n 3) n)(else(+ (ex1-f (- n 1)) (* 2 (ex1-f (- n 2))) (* 3 (ex1-f (- n 3))))))) (define (expmod base exp m)(cond ((= exp 0) 1)((even? exp)(remainder (square (expmod base (/ exp 2) m))m))(else(remainder (* base (expmod base (- exp 1) m))m)))) ; (define (expmod base exp m) ; (remainder (fast-expt base exp) m)) (define (fermat-test n)(define (try-it a)(= (expmod a n n) a))(try-it (+ 1 (random (- n 1)))))(define (fast-prime? n times)(cond ((= times 0) true)((fermat-test n) (fast-prime? n (- times 1)))(else false))) ; (define (sum term a next b) ; (if (> a b) ; 0 ; (+ (term a) ; (sum term (next a) next b))));ex 1.30 (define (sum term a next b)(define (iter a result)(if (> a b)result(iter (next a) (+ (term a) result))))(iter a 0));ex 1.31 (define (product term a next b)(define (iter a result)(if (> a b)result(iter (next a) (* (term a) result))))(iter a 1));ex 1.32 (define (accumulate1 combiner null-value term a next b)(define (iter a result)(if (> a b)result(iter (next a) (combiner (term a) result))))(iter a null-value));ex 1.33 (define (filtered-accumulate filter combiner null-value term a next b)(define (iter a result)(if (> a b)result(if (filter a)(iter (next a) (combiner (term a) result))(iter (next a) result))))(iter a null-value)) (define (inc n) (+ n 1))(define (cube x) (* x x x))(define (sum-cubes a b)(sum cube a inc b))(define (identity x) x)(define (sum-integers a b)(accumulate1 + 0 identity a inc b))(define (product-integers a b)(accumulate1 * 1 identity a inc b))(define (sum-integers-even a b)(filtered-accumulate even? + 0 identity a inc b))(define (product-integers-even a b)(filtered-accumulate even? * 1 identity a inc b)) ; (define (sum-integers a b) ; (sum identity a inc b)) ; (define (product-integers a b) ; (product identity a inc b)) )

?

轉(zhuǎn)載于:https://www.cnblogs.com/sniperHW/archive/2013/05/22/3093818.html

總結(jié)

以上是生活随笔為你收集整理的sicp第一章部分习题解答的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。