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)
集合
SICP的一些练习题的更多相关文章
- sicp第1章
牛顿迭代法求平方: (define (sqrt-iter guess x) (if (good-enough? guess x) guess (sqrt-iter (improve guess x) ...
- Lisp和SICP
大概不少programmer都看过<黑客与画家>,作者用了整整一章的篇幅讨论Lisp的强大.我自然就会手痒痒. 几个月前,几天内攻城略地搞定了Python,用的方法便是 ...
- Linux基础练习题(二)
Linux基础练习题(二) 1.复制/etc/skel目录为/home/tuer1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限. [root@www ~]# cp -r ...
- shell 脚本之 shell 练习题汇总
整理了一些 shell 相关的练习题,记录到这里. 1. 请按照这样的日期格式 xxxx-xx-xx 每日生成一个文件,例如:今天生成的文件为 2013-09-23.log, 并且把磁盘的使用情况写到 ...
- MySQL练习题
MySQL练习题 一.表关系 请创建如下表,并创建相关约束 二.操作表 1.自行创建测试数据 2.查询“生物”课程比“物理”课程成绩高的所有学生的学号: 3.查询平均成绩大于60分的同学的学号和平均成 ...
- MySQL练习题参考答案
MySQL练习题参考答案 2.查询“生物”课程比“物理”课程成绩高的所有学生的学号: 思路: 获取所有有生物课程的人(学号,成绩) - 临时表 获取所有有物理课程的人(学号,成绩) - 临时表 根据[ ...
- mysql练习题-查询同时参加计算机和英语考试的学生的信息-遁地龙卷风
(-1)写在前面 文章参考http://blog.sina.com.cn/willcaty. 针对其中的一道练习题想出两种其他的答案,希望网友给出更多回答. (0) 基础数据 student表 +-- ...
- 【UOJ#228】基础数据结构练习题 线段树
#228. 基础数据结构练习题 题目链接:http://uoj.ac/problem/228 Solution 这题由于有区间+操作,所以和花神还是不一样的. 花神那道题,我们可以考虑每个数最多开根几 ...
- 【Java EE 学习 28 下】【Oracle面试题2道】【Oracle练习题3道】
一.已知程序和数据 create table test1 (id int primary key, name ), money int); ,); ,); ,); ,); 要求根据下图写出相应的sql ...
随机推荐
- CUDA基本概念
CUDA计算模型 CUDA中计算分为两部分,串行部分在Host上执行,即CPU,而并行部分在Device上执行,即GPU. 相比传统的C语言,CUDA增加了一些扩展,包括了库和关键字. CUDA代码提 ...
- svn文件清理Bat脚本
@echo On@Rem C:\Users\caoxiancc\Desktop\Ueditor-thinkphp-master\Ueditor --svn跟路径@PROMPT [Com] @for / ...
- RPI-Wireless-Hotspot
http://elinux.org/RPI-Wireless-Hotspot What does it do? This project configures your Raspberry Pi to ...
- 使用grep要注意的地方
[maijunjin@localhost testGrep]$ ./ #没有结果 [maijunjin@localhost testGrep]$ . #没有结果 [maijunjin@localhos ...
- 数据结构上机实验dfs&&bfs遍历图
#include<stdio.h> #include<string.h> #include<stdlib.h> #include<queue> #inc ...
- 4.22 注入js需要加 addjavascriptinterface
由于项目需要,再次使用到了android的webview,webview要加载的页面是html5的页面: 需要有点击webview中的控件的交互,所以需要在android应用中注入一个js对象: 通过 ...
- 一种从JSON数据创建Java类的高效办法
<一种从JSON数据创建Java类的高效办法> 作者:chszs,转载需注明.博客主页:http://blog.csdn.net/chszs JSON格式的数据经常会遇到,比如调用Web服 ...
- Linux下JDK安装位置
新手在Linux上安装JDK时,不知道应该将JDK安装在哪比较合适.首先简要了解下Linux中部分目录的作用. /bin---用来贮存用户命令./usr/bin 也被用来贮存用户命令. /sbin- ...
- Go2Shell
1.背景 windows系统可以轻而易举地拿到文件所在目录, 但是mac显得想拿文件目录有点蛋疼.而Go2Shell可以快速定位到文件所在的目录. 2.安装配置 选择默认打开的终端软件 3.使用 进入 ...
- 【转】Netty那点事(四)Netty与Reactor模式
[原文]https://github.com/code4craft/netty-learning/blob/master/posts/ch4-reactor.md 一:Netty.NIO.多线程? 时 ...