- 浏览: 215956 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
andy1015:
请教下楼主rtx问题 ,可以么
用HttpClient实现同步RTX -
cgp17:
请教:Chukwa支持Push数据吗?目前看到的都是Polli ...
基于Hadoo的日志收集框架---Chukwa的源码分析(适配器、代理) -
jimmee:
尼玛, 现在iteye的质量下降到何种水准了.
Mahout协同过滤框架Taste的源码分析 -
aubdiy:
aubdiy 写道我擦。。。。 这你叫分析才看到, 还有个 “ ...
Mahout协同过滤框架Taste的源码分析 -
aubdiy:
我擦。。。。 这你叫分析
Mahout协同过滤框架Taste的源码分析
练习2.24
;; 嵌套结构的list 1 ]=> (list 1 (list 2 (list 3 4))) ;Value : (1 (2 (3 4))) * / \ 1 * / \ 2 * / \ 3 4
练习2.25
;; (1 3 (5 7) 9) 1 ]=> (define list1 (list 1 3 (list 5 7) 9)) 1 ]=> list1 ;Value : (1 3 (5 7) 9) 1 ]=> (car (cdr (car (cdr (cdr list1))))) ;Value: 7 ;; ((7)) 1 ]=> (define list1 (list (list 7))) 1 ]=> list1 ;Value : ((7)) 1 ]=> (car (car list1)) ;Value: 7 ;; (1 (2 (3 (4 (5 (6 7)))))) 1 ]=> (define list1 (list 1 (list 2 (list 3 (list 4 (list 5 (list 6 7))))))) 1 ]=> list1 ;Value : (1 (2 (3 (4 (5 (6 7)))))) 1 ]=> (car (cdr (car (cdr (car (cdr (car (cdr (car (cdr (car (cdr list1)))))))))))) ;Value: 7
练习2.26
1 ]=> (append x y) ;Value : (1 2 3 4 5 6) 1 ]=> (cons x y) ;Value : ((1 2 3) 4 5 6) 1 ]=> (list x y) ;Value : ((1 2 3) (4 5 6))
练习2.27
(define (deep-reverse items) (cond ((null? items) '()) ((pair? (car items)) (append (deep-reverse (cdr items)) (list (deep-reverse (car items))))) (else (append (deep-reverse (cdr items)) (list (car items))))))
练习2.28
;; 采用递归的方式,如果是序对就将左子树和右子树的结果拼接,否则直接拼接 (define (fringe items) (define (frings-iter things answer) (cond ((null? things) answer) ((pair? things) (append (frings-iter (car things) answer) (frings-iter (cdr things) answer))) (else (append answer (list things))))) (frings-iter items '()))
练习2.29
;; a (define (left-branch mobile) (car mobile)) (define (right-branch mobile) (cdr mobile)) (define (branch-length branch) (car branch)) (define (branch-structure branch) (car (cdr branch))) ;; b ;; 先检查是不是二叉活动体,如果是则递归求两个分支的重量 ;; 再检查分支的structure是否仍然是活动体, 如果是则递归求structure的重量 ;; 最后对于最简单的分支情况直接相加重量 (define (total-weight mobile) (define (mobile-flag m) (pair? (left-branch m))) (define (branch-flag m) (pair? (branch-structure m))) (define (total-weight-iter m tw) (cond ((null? m) tw) ((mobile-flag m) (+ (total-weight-iter (left-branch m) tw) (total-weight-iter (right-branch m) tw))) ((branch-flag m) (+ (total-weight-iter (branch-structure m) tw))) (else (+ tw (branch-structure m))))) (total-weight-iter mobile 0)) ;; 或者可以将活动体的重量看做是两个分支重量之和 ;; 但是在对分支求重量时仍然要区分是否还有分支 (define (total-weight mobile) (if (pair? (left-branch mobile)) (+ (branch-weight (left-branch mobile)) (branch-weight (right-branch mobile))) (branch-weight mobile))) (define (branch-weight branch) (let ((structure (if (null? (right-branch branch)) (left-branch branch) (branch-structure branch)))) (if (pair? structure) (branch-weight structure) structure))) ;; c ;; 首先定义分支的力矩,依据其是否有分支分别处理 (define (branch-value branch) (if (null? (right-branch branch)) (* (branch-length (left-branch branch)) (branch-weight branch)) (* (branch-length branch) (branch-weight branch)))) ;; 然后实现活动体的检测过程:两个分支平衡且两个分支的力矩相等 (define (check-balance mobile) (if (pair? (left-branch mobile)) (and (check-balance (left-branch mobile)) (check-balance (car (right-branch mobile))) (= (branch-value (left-branch mobile)) (branch-value (right-branch mobile)))) #t)) ;; d ;; 需要对structure过程修改 (define (branch-structure branch) ;;(car (cdr branch))) (cdr branch)) (define (check-balance mobile) (if (pair? (left-branch mobile)) (and (check-balance (left-branch mobile)) ;;(check-balance (car (right-branch mobile))) (check-balance (right-branch mobile)) (= (branch-value (left-branch mobile)) (branch-value (right-branch mobile)))) #t)) ;; 验证 (define mtest (make-mobile (make-branch 3 4) (make-branch 2 6))) 1 ]=> (total-weight mtest) ;Value: 10 1 ]=> (check-balance mtest) ;Value: #t
练习2.30
(define (square-tree tree) (cond ((null? tree) '()) ((not (pair? tree)) (square tree)) (else (cons (square-tree (car tree)) (square-tree (cdr tree)))))) (define (map-square-tree tree) (map (lambda (sub-tree) (if (pair? sub-tree) (map-square-tree sub-tree) (square sub-tree))) tree)) 1 ]=> (square-tree (list 1 (list 2 (list 3 4) 5) (list 6 7))) ;Value : (1 (4 (9 16) 25) (36 49)) 1 ]=> (map-square-tree (list 1 (list 2 (list 3 4) 5) (list 6 7))) ;Value : (1 (4 (9 16) 25) (36 49))
练习2.31
(define (tree-map fun tree) (map (lambda (sub-tree) (if (pair? sub-tree) (tree-map fun sub-tree) (fun sub-tree))) tree)) 1 ]=> (define (square-tree-test tree) (tree-map square tree)) ;Value : square-tree-test 1 ]=> (square-tree-test (list 1 (list 2 (list 3 4) 5) (list 6 7))) ;Value : (1 (4 (9 16) 25) (36 49))
练习2.32
;; 仿照换零钱的例子 ;; rest取不包含(car s)元素的所有剩余元素的组合 ;; 则应加上(car s)元素与所有剩余元素的组合 (define (subsets s) (if (null? s) (list '()) (let ((rest (subsets (cdr s)))) (append rest (map (lambda (r) (append (list (car s)) r)) rest))))) 1 ]=> (subsets s) ;Value : (() (3) (2) (2 3) (1) (1 3) (1 2) (1 2 3))
发表评论
-
SICP学习笔记 2.3.2 实例:符号求导
2012-12-12 09:59 1302练习2.56 (define (deriv ... -
SICP学习笔记 2.2.4 实例:一个图形语言
2012-12-11 21:49 1277练习2.44 (define (up-spl ... -
SICP学习笔记 2.2.3 序列作为一种约定的接口
2012-09-14 17:48 1043练习2.33 ;; map过程即为使用过程p ... -
SICP学习笔记 2.2.1 序列的表示
2012-08-31 17:31 1162练习2.17 ;; 直接利用已经实现的lis ... -
SICP学习笔记 2.1.4 扩展练习:区间算术
2012-08-28 17:12 1309练习2.7 ;; 抽象对象"区间& ... -
SICP学习笔记 2.1.3 数据意味着什么
2012-08-26 11:07 1104练习2.4 (define (new-con ... -
SICP学习笔记 2.1.2 抽象屏障
2012-08-18 22:05 879练习2.2 (define (make-poin ... -
SICP学习笔记 2.1.1 实例: 有理数的算术运算
2012-08-18 21:44 857练习 2.1 (define (make-r ... -
SICP学习笔记 1.3.4 过程作为返回值
2012-08-12 11:44 965练习 1.40 (define (cubic ... -
SICP学习笔记 1.3.3 过程作为一般性的方法
2012-08-12 11:38 869练习 1.35 φ^2 = φ+1 == ... -
SICP学习笔记 1.3.2 用lambda构造过程
2012-07-13 08:50 750练习 1.34 > (d ... -
SICP学习笔记 1.3.1 过程作为参数
2012-07-13 08:44 901练习1.29 (define (sum ... -
SICP学习笔记 1.2.6 实例:素数检测
2012-06-04 11:08 1038练习1.22 ;; runtime函数在stk、ra ... -
SICP学习笔记 1.2.5 最大公约数
2012-05-17 17:35 815练习 1.20 (define (gcd a ... -
SICP学习笔记 1.2.4 求幂
2012-05-11 18:03 879练习1.16 根 ... -
SICP学习笔记 1.2.3 增长的阶
2012-05-09 21:06 1460练习1.14 (define (count-chan ... -
SICP学习笔记 1.1.7 实例:使用牛顿法求平方根
2012-04-25 18:02 1293练习1.6 应用序会对 (def ... -
SICP学习笔记 1.2.2 树形递归
2012-04-25 18:18 915练习1.11 递归过程 (defin ... -
SICP学习笔记 1.2.1 线性的递归和迭代
2012-04-24 17:22 846练习1.9 对于过程 (define ... -
SICP学习笔记 1.1.6 条件表达式和谓词
2012-04-24 17:18 816练习1.1 10 12 8 3 6 ...
相关推荐
sicp in python 中文版 sicp in python 中文版 sicp in python 中文版 !!!download>>>https://github.com/wizardforcel/sicp-py-zh
SICP中文第二版SICP中文第二版SICP中文第二版SICP中文第二版SICP中文第二版
^_^这本教科书所使用的是C语言,也许很多人会说C语言已经过时了,但是,我认为在数据结构的学习中,应该用尽量简单的语言,以免进入了语言的细枝末节中,反而冲淡了主题。实际上在国外的许多大学中(甚至中学),...
SICP-Python版本
Python SICP epub版本,很适合学习抽象的思想,用Python版本比lisp更实用
SICP 使用的scheme解释器 以前叫DrScheme
Learn_sicp 学习sicp的一些代码
sicp 2.2.4节图形语言的racket程序包,配置路径,C:\Users\Administrator\AppData\Roaming\Racket
SICP 解题集
SICP实践 用球拍锻炼身体
sicp_notes SICP笔记和练习 资源 笔记 使用第一版,最高为ex 1.24。 从ex 1.31开始切换到第二版。
实际上在国外的许多大学中(甚至中学),数据结构和算法分析的课程是选用Scheme(Scheme语言是Lisp的一个现代变种、方言,诞生于1975年)的,例如MIT麻省理工大学极其著名的SICP课程。呵呵,语言又能说明什么呢?...
SICP CHINESE ENGLISH THE SECOND EDITION SICP CHINESE ENGLISH THE SECOND EDITION
SICP 习题答案 计算机程序的构造和解释 1-3章 习题答案
这是一本MIT的计算机系的必修课的教科书。一本十分权威经典的书籍。相信对大家很有帮助
sicp in python 中文版 sicp in python 中文版 sicp in python 中文版 download : https://github.com/wizardforcel/sicp-py-zh
请参考那些正在学习SICP的人。 笔记 如果你想在 gauch 中使用随机函数 (use math.mt-random) (define m (make <mersenne> :seed (sys-time))) (mt-random-integer m 1000) (define (random n) (mt-random-integer ...
SICP习题解答,主要第一章的内容习题答案
资源来自pypi官网。 资源全名:sicp-0.0.1b102.dev4.tar.gz