大魔法师
SICP
CPJLJ
我承认这个递归我有赌的成分
展开
-
实例:换零钱方式的统计
将现金数a换成除第一种硬币之外的所有为他硬币的不同方式数目,加上将硬币a-d换成所有类型的硬币的不同数目,其中的d是第一种硬币的币值(define (count-change amount) (define (cc amount kinds-of-coins) (cond ((= amount 0) 1) ((or (< amount 0) ...原创 2019-12-21 13:06:31 · 310 阅读 · 0 评论 -
1.1组织块结构
(define (sqrt x) (define (good-enough? guess) (< (abs (- (square guess) x)) 0.001)) (define (improve guess) (average guess(/ x guess))) (define (sqrt-iter guess) (if (good-enough?...原创 2019-12-20 08:55:39 · 186 阅读 · 0 评论 -
练习1.8
求立方根的牛顿法(define (sqrt-iter guess x) (if (good-enough? guess x) guess (sqrt-iter (improve guess x) x)))(define (improve guess x) (/ (+ (/ x (* guess guess))(* 2 gue...原创 2019-12-20 08:26:37 · 126 阅读 · 0 评论 -
练习1.7
改进good-enough监视猜测值在从一次迭代到下一次迭代的变化情况,当改变值相对于猜测值的比率很小时就结束。#lang sicp(define (sqrt-iter guess x) (if (good-enough? guess x) guess (sqrt-iter (improve guess x) x)))(de...原创 2019-12-19 21:26:07 · 209 阅读 · 0 评论 -
采用牛顿法求平方根
(define (sqrt-iter guess x) (if (good-enough? guess x) guess (sqrt-iter (improve guess x) x)))(define (improve guess x) (average guess (/ x guess)))(define (average...原创 2019-12-19 21:02:43 · 157 阅读 · 0 评论 -
练习1.5
判断采用“正则序”(完全展开后规约)还是“引用序”(先求值参数而后应用)?(define (p) (0))(define (test x y) (if (= x 0) 0 y))(test 0 (p))这个结果报错所以我的解释器(DrRacket)采用“应用序” 先求值...原创 2019-12-19 20:30:11 · 169 阅读 · 0 评论 -
练习1.3
三者较大两数之和三者之和减去最小值即为较大两数之和(define (sum x y z) (+ x y z))(define (min x y z) (if (and (< x y)(< x z)) x (if (< y z) y z))) (define (max-sum x...原创 2019-12-19 20:06:44 · 118 阅读 · 0 评论