摘要: (define (first-denomination kinds-of-coin) (cond ((= kinds-of-coin 1) 1) ((= kinds-of-coin 2) 5) ((= kinds-of-coin 3) 10) ((= kinds-of-coin 4) 25) ((= 阅读全文
posted @ 2017-11-22 23:16 R4mble 阅读(268) 评论(0) 推荐(0)
摘要: 树形递归:计算步骤 随输入 指数性 增长,空间 随输入 线性 增长. 线性迭代:计算步骤 随输入 线性 增长,空间 随输入 线性 增长. 用java写出来看看到底有多厉害: 树形递归程序运行时间:70805ms 而线性迭代绝大部分时候都是0ms. (Java里面函数名不允许 - 这个符号) 阅读全文
posted @ 2017-11-22 20:56 R4mble 阅读(345) 评论(0) 推荐(1)
摘要: (define (A x y) (cond ((= y 0) 0) ((= x 0) (* 2 y)) ((= y 1) 2) (else (A (- x 1) (A x (- y 1)))))) (A 1 10) (A 2 4) (A 3 3) (define (f n) (A 0 n))(f 0 阅读全文
posted @ 2017-11-22 19:59 R4mble 阅读(171) 评论(0) 推荐(0)
摘要: (define (plus-Recursive a b) (if (= a 0) b (inc (plus-Recursive (dec a) b)))) (define (inc n) (+ n 1)) (define (dec n) (- n 1)) (plus-Recursive 3 5) 从 阅读全文
posted @ 2017-11-22 19:45 R4mble 阅读(178) 评论(0) 推荐(0)
摘要: 递归: (define (factorial n) (if (= n 1) 1 (* n (factorial(- n 1))))) (factorial 3) 迭代: (define (factorial n) (fact-iter 1 1 n)) (define (fact-iter produ 阅读全文
posted @ 2017-11-22 19:29 R4mble 阅读(164) 评论(0) 推荐(0)
摘要: (define (cube-root x) (cube-root-iter 1.0 x)) (define (cube-root-iter guess x) (if (good-enough? guess x) guess (cube-root-iter (improve guess x) x))) 阅读全文
posted @ 2017-11-22 19:01 R4mble 阅读(226) 评论(0) 推荐(0)
摘要: (define (sqrt-iter guess x) (if (good-enough? guess (improve guess x)) (improve guess x) (sqrt-iter (improve guess x) x))) (define (improve guess x)(a 阅读全文
posted @ 2017-11-22 18:50 R4mble 阅读(201) 评论(0) 推荐(0)
摘要: <一> (define (new-if predicate then-clause else-clause) (cond (predicate then-clause) (else else-clause))) (new-if (= 2 3) 0 5)(new-if (= 1 1) 0 5) new 阅读全文
posted @ 2017-11-22 13:38 R4mble 阅读(272) 评论(0) 推荐(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))) 阅读全文
posted @ 2017-11-22 13:04 R4mble 阅读(184) 评论(0) 推荐(0)
摘要: (define (p) (p))(define (test x y) (if (= x 0) 0 y))(test 0 (p)) 哇,这么快就印证了我的想法了吗. 首先用R5RS跑一遍,啥都没有.然后切换成Lazy Racket,结果为0. 解释:前者是应用序,p一传进来就求值,不断的调用自己,无限 阅读全文
posted @ 2017-11-22 12:10 R4mble 阅读(304) 评论(0) 推荐(0)
摘要: (define (a-plus-abs-b a b) (if (> b 0) (+ a b) (- a b)) )(define (a-plus-abs-b-book a b) ((if (> b 0) + -) a b) )(a-plus-abs-b 1 -1)(a-plus-abs-b-book 阅读全文
posted @ 2017-11-22 11:56 R4mble 阅读(191) 评论(0) 推荐(0)
摘要: (define (SumOfTwoLarge x y z) (if (and (<= x y) (<= x z)) (+ (* y y) (* z z)) (SumOfTwoLarge y x z)) )(SumOfTwoLarge 0 2 2) 感觉我这个很取巧啊,哈哈哈哈. 我还是有点不习惯把函 阅读全文
posted @ 2017-11-22 11:44 R4mble 阅读(120) 评论(0) 推荐(0)
摘要: (/ (+ 5 4(- 2 (- 3 (+ 6 (/ 4 5))))) (* 3 (- 6 2) (- 2 7))) 注意: (- 1 1 1 1)这样写也可以 阅读全文
posted @ 2017-11-22 11:27 R4mble 阅读(207) 评论(0) 推荐(0)
摘要: (define a 3) (define b (+ a 1)) b (+ a b(* a b)) (= a b) (if (and (> b a) (< b (* a b))) b a) (cond ((= a 4) 6) ((= b 4) (+ 6 7 a)) (else 25)) (+ 2 (i 阅读全文
posted @ 2017-11-22 11:26 R4mble 阅读(315) 评论(0) 推荐(0)