SICP
lang801213
这个作者很懒,什么都没留下…
展开
-
sicp 2.10
Exercise 2.10. Ben Bitdiddle, an expert systems programmer, looks over Alyssa's shoulder and comments that it is not clear what it means to divide by an interval that spans zero. Modify Alyssa's code...2011-07-19 18:24:35 · 77 阅读 · 0 评论 -
sicp 2.18
Exercise 2.18. Define a procedure reverse that takes a list as argument and returns a list of the same elements in reverse order: (reverse (list 1 4 9 16 25))(25 16 9 4 1) (def...2011-07-21 23:48:23 · 85 阅读 · 0 评论 -
sicp 2.19
Exercise 2.19. Consider the change-counting program of section 1.2.2. It would be nice to be able to easily change the currency used by the program, so that we could compute the number of ways to ...2011-07-24 00:19:01 · 65 阅读 · 0 评论 -
sicp 2.25
Exercise 2.25. Give combinations of cars and cdrs that will pick 7 from each of the following lists: (1 3 (5 7) 9)((7))(1 (2 (3 (4 (5 (6 7)))))) (define a '(1 3 (5 7) 9))(defi...2011-07-25 14:35:42 · 66 阅读 · 0 评论 -
sicp 2.26
Exercise 2.26. Suppose we define x and y to be two lists: (define x (list 1 2 3))(define y (list 4 5 6)) What result is printed by the interpreter in response to evaluating each of the ...2011-07-25 14:38:24 · 67 阅读 · 0 评论 -
sicp 2.27
Exercise 2.27. Modify your reverse procedure of exercise 2.18 to produce a deep-reverse procedure that takes a list as argument and returns as its value the list with its elements reversed and with a...2011-07-25 14:46:50 · 100 阅读 · 0 评论 -
sicp 2.17
Exercise 2.17. Define a procedure last-pair that returns the list that contains only the last element of a given (nonempty) list: (last-pair (list 23 72 149 34))(34) (define (la...2011-07-21 23:42:13 · 55 阅读 · 0 评论 -
sicp 2.16
Exercise 2.16. Explain, in general, why equivalent algebraic expressions may lead to different answers. Can you devise an interval-arithmetic package that does not have this shortcoming, or is thi...2011-07-21 23:27:24 · 95 阅读 · 0 评论 -
sicp 2.11
Exercise 2.11. In passing, Ben also cryptically comments: ``By testing the signs of the endpoints of the intervals, it is possible to break mul-interval into nine cases, only one of which requires mo...2011-07-19 19:30:40 · 101 阅读 · 0 评论 -
sicp 2.12
Exercise 2.12. Define a constructor make-center-percent that takes a center and a percentage tolerance and produces the desired interval. You must also define a selector percent that produces the per...2011-07-19 19:44:17 · 74 阅读 · 0 评论 -
sicp 2.13
Exercise 2.13. Show that under the assumption of small percentage tolerances there is a simple formula for the approximate percentage tolerance of the product of two intervals in terms of the toleran...2011-07-20 10:06:25 · 79 阅读 · 0 评论 -
sicp 1.35
x=1+1/x的不动点: (define (fixed-point f first-guess) (let ((eps 0.000001)) (define (close-enough? g1 g2) (< (abs (- g1 g2)) eps)) (define (try x) (if (close-enough? x (f ...原创 2011-03-14 21:50:32 · 57 阅读 · 0 评论 -
sicp 1.37
(define (cont-frac n d k) (define (iter k result) (if (= k 0) result (iter (- k 1) (/ (n k) (+ (d k) result))))) (iter k 0))(define (cont k) (let ((eps 0.00005) ...原创 2011-03-14 22:55:09 · 67 阅读 · 0 评论 -
sicp 1.38
(define (cont-frac n d k) (define (iter k result) (if (= k 0) result (iter (- k 1) (/ (n k) (+ (d k) result))))) (iter k 0))(define (cont k) (let ((value (cont-frac...原创 2011-03-14 23:08:50 · 61 阅读 · 0 评论 -
sicp 2.14
Exercise 2.14. Demonstrate that Lem is right. Investigate the behavior of the system on a variety of arithmetic expressions. Make some intervals Aand B, and use them in computing the expressions A/A ...2011-07-21 23:16:14 · 104 阅读 · 0 评论 -
sicp 2.15
Exercise 2.15. Eva Lu Ator, another user, has also noticed the different intervals computed by different but algebraically equivalent expressions. She says that a formula to compute with intervals us...2011-07-21 23:17:31 · 87 阅读 · 0 评论 -
sicp 2.28
Exercise 2.28. Write a procedure fringe that takes as argument a tree (represented as a list) and returns a list whose elements are all the leaves of the tree arranged in left-to-right order. For ...2011-07-25 15:00:14 · 101 阅读 · 0 评论 -
sicp 2.29
Exercise 2.29. A binary mobile consists of two branches, a left branch and a right branch. Each branch is a rod of a certain length, from which hangs either a weight or another binary mobile. We c...2011-11-16 13:51:33 · 94 阅读 · 0 评论 -
sicp 2.43
Exercise 2.43. Louis Reasoner is having a terrible time doing exercise 2.42. His queens procedure seems to work, but it runs extremely slowly. (Louis never does manage to wait long enough for it t...2011-11-25 14:08:09 · 91 阅读 · 0 评论 -
sicp 2.44
Exercise 2.44. Define the procedure up-split used by corner-split. It is similar to right-split, except that it switches the roles ofbelow and beside. 参考right-split,比较简单: (define (up-split...2011-11-28 17:08:24 · 86 阅读 · 0 评论 -
sicp 2.45
Exercise 2.45. Right-split and up-split can be expressed as instances of a general splitting operation. Define a procedure splitwith the property that evaluating (define right-split (split bes...2011-11-28 17:47:31 · 73 阅读 · 0 评论 -
sicp 2.46
Exercise 2.46. A two-dimensional vector v running from the origin to a point can be represented as a pair consisting of an x-coordinate and a y-coordinate. Implement a data abstraction for vectors...2011-11-28 17:53:58 · 71 阅读 · 0 评论 -
sicp 2.47
Exercise 2.47. Here are two possible constructors for frames: (define (make-frame origin edge1 edge2) (list origin edge1 edge2))(define (make-frame origin edge1 edge2) (cons origin (cons edg...2011-11-28 18:02:46 · 66 阅读 · 0 评论 -
sicp 2.48
Exercise 2.48. A directed line segment in the plane can be represented as a pair of vectors -- the vector running from the origin to the start-point of the segment, and the vector running from the or...2011-11-28 18:07:08 · 79 阅读 · 0 评论 -
sicp 2.49
Exercise 2.49. Use segments->painter to define the following primitive painters:a. The painter that draws the outline of the designated frame.b. The painter that draws an ``X'' by connect...2011-12-06 15:25:37 · 83 阅读 · 0 评论 -
sicp 2.50
Exercise 2.50. Define the transformation flip-horiz, which flips painters horizontally, and transformations that rotate painters counterclockwise by 180 degrees and 270 degrees. (define (flip-...2011-12-06 15:33:53 · 80 阅读 · 0 评论 -
sicp 2.42
Exercise 2.42. Figure 2.8: A solution to the eight-queens puzzle. The ``eight-queens puzzle'' asks how to place eight queens on a chessboard so that no queen is in check...2011-11-25 13:06:01 · 124 阅读 · 0 评论 -
sicp 2.41
Exercise 2.41. Write a procedure to find all ordered triples of distinct positive integers i, j, and k less than or equal to a given integer n that sum to a given integer s. (define (find-t...2011-11-21 16:58:17 · 72 阅读 · 0 评论 -
sicp 2.32
Exercise 2.32. We can represent a set as a list of distinct elements, and we can represent the set of all subsets of the set as a list of lists. For example, if the set is (1 2 3), then the set of...2011-11-16 15:06:43 · 101 阅读 · 0 评论 -
sicp 2.33
Exercise 2.33. Fill in the missing expressions to complete the following definitions of some basic list-manipulation operations as accumulations: (define (map p sequence) (accumulate (lambda ...2011-11-16 15:51:24 · 61 阅读 · 0 评论 -
sicp 2.35
Exercise 2.35. Redefine count-leaves from section 2.2.2 as an accumulation: (define (count-leaves t) (accumulate <??> <??> (map <??> <??>))) (define (accum...2011-11-17 17:17:46 · 97 阅读 · 0 评论 -
sicp 2.26
Exercise 2.36. The procedure accumulate-n is similar to accumulate except that it takes as its third argument a sequence of sequences, which are all assumed to have the same number of elements. It...2011-11-17 17:39:28 · 83 阅读 · 0 评论 -
sicp 2.39
Exercise 2.39. Complete the following definitions of reverse (exercise 2.18) in terms of fold-right and fold-left from exercise 2.38: (define (reverse sequence) (fold-right (lambda (x y) <...2011-11-18 01:42:18 · 64 阅读 · 0 评论 -
sicp 2.53
Exercise 2.53. What would the interpreter print in response to evaluating each of the following expressions? (list 'a 'b 'c)(list (list 'george))(cdr '((x1 x2) (y1 y2)))(cadr '((x1 x2) (y1 y2...2013-09-13 11:22:25 · 79 阅读 · 0 评论 -
sicp 2.9
Exercise 2.9. The width of an interval is half of the difference between its upper and lower bounds. The width is a measure of the uncertainty of the number specified by the interval. For some arithm...2011-07-19 18:16:28 · 59 阅读 · 0 评论 -
sicp 1.1
表达式求值,斜体部分为输出。 > 1010> (+ 5 3 4)12> (- 9 1)8> (/ 6 2)3> (+ (* 2 4) (- 4 6))6> (define a 3)> (define b (+ a 1))> (+ a b (* a b))19>...2009-05-25 15:59:16 · 66 阅读 · 0 评论 -
sicp 1.14
如下过程: (define (count-change amount) (cc amount 5))(define (cc amount kinds-of-coins) (cond ((= amount 0) 1) ((or (< amount 0) (= kinds-of-coins 0)) 0) (else (+ (cc amount (- kin...2009-06-02 13:34:20 · 84 阅读 · 0 评论 -
sicp 1.15
利用三角恒等式:sin x = 3sin(x/3) - 4sin(x/3)^3,求值sin x,当x足够小时,sin x = x。过程如下 (define (sine angle) (if (<= (abs angle) 0.1) angle (p (sine (/ angle 3.0)))))(define (p x) (- (* 3 x) ...2009-06-02 14:11:20 · 60 阅读 · 0 评论 -
sicp 1.17
利用加法做乘法,对数计算步数。 (define (* a b) (cond ((= b 0) 0) ((even? b) (* (double a) (halve b))) (else (+ a (* a (- b 1))))))(define (double x) (+ x x))(define (halve x) (...原创 2009-12-31 12:56:30 · 83 阅读 · 0 评论 -
sicp 1.13
证明Fibonacci数列F(n)是最接近(a^n) / sqrt(5)的整数,其中a=(1+sqrt(5)) / 2。 F(n) = 0, n = 0 1, n = 1 F(n-1) + F(n-2), n > 1 此递归式的特征方程为 C(t) = t^2 - t - 1 = 0,求解得t1 = (1+sqrt(5)) / 2,...2009-06-02 10:48:21 · 88 阅读 · 0 评论