`
Bloodwolf
  • 浏览: 88774 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论
文章列表

sicp 2.40

    博客分类:
  • SICP
Exercise 2.40.  Define a procedure unique-pairs that, given an integer n, generates the sequence of pairs (i,j) with 1< j< i< n. Useunique-pairs to simplify the definition of prime-sum-pairs given above.     (define (unique-pairs n) (accumulate append '() ...

sicp 2.39

    博客分类:
  • SICP
  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) <??>) nil sequence))(define (reverse sequence)  (fold-left (lambda (x y) <??>) nil sequence) ...

sicp 2.38

    博客分类:
  • SICP
Exercise 2.38.  The accumulate procedure is also known as fold-right, because it combines the first element of the sequence with the result of combining all the elements to the right. There is also a fold-left, which is similar to fold-right, except that it combines elements working in the opposit ...

sicp 2.37

    博客分类:
  • SICP
Exercise 2.37.  Suppose we represent vectors v = (vi) as sequences of numbers, and matrices m = (mij) as sequences of vectors (the rows of the matrix). For example, the matrix   is represented as the sequence ((1 2 3 4) (4 5 6 6) (6 7 8 9)). With this representation, we can use sequence operat ...

sicp 2.26

    博客分类:
  • SICP
  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 applies the designated accumulation procedure to combine all the first elements of the sequences, al ...

sicp 2.35

    博客分类:
  • SICP
Exercise 2.35.  Redefine count-leaves from section 2.2.2 as an accumulation:   (define (count-leaves t)  (accumulate <??> <??> (map <??> <??>)))     (define (accumulate op initial sequence) (if (null? sequence) initial (op (car sequence) ...

sicp 2.34

    博客分类:
  • SICP
  Exercise 2.34.  Evaluating a polynomial in x at a given value of x can be formulated as an accumulation. We evaluate the polynomial   using a well-known algorithm called Horner's rule, which structures the computation as   In other words, we start with an, multiply by x, add an-1, multiply ...

sicp 2.33

    博客分类:
  • SICP
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 (x y) <??>) nil sequence))(define (append seq1 seq2)  (accumulate cons <??> <??>))( ...

sicp 2.32

    博客分类:
  • SICP
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 all subsets is (() (3) (2) (2 3) (1) (1 3) (1 2) (1 2 3)). Complete the following definition of a pr ...

sicp 2.31

    博客分类:
  • SICP
Exercise 2.31.  Abstract your answer to exercise 2.30 to produce a procedure tree-map with the property that square-tree could be defined as     (define (square-tree tree) (tree-map square tree))   (define (tree-map operation tree) (map (lambda (sub-tree) (if (pair? sub-tree ...

sicp 2.30

    博客分类:
  • SICP
Exercise 2.30.  Define a procedure square-tree analogous to the square-list procedure of exercise 2.21. That is, square-list should behave as follows:     (square-tree (list 1       (list 2 (list 3 4) 5)       (list 6 7)))(1 (4 (9 16) 25) (36 49))   Define square-tree both directly (i.e., wit ...

sicp 2.29

    博客分类:
  • SICP
  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 can represent a binary mobile using compound data by constructing it from two branches (for example, u ...

sicp 2.28

    博客分类:
  • SICP
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 example,     (define x (list (list 1 2) (list 3 4)))(fringe x)(1 2 3 4)(fringe (list x x))(1 2 3 4 ...

sicp 2.27

    博客分类:
  • SICP
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 all sublists deep-reversed as well. For example,     (define x (list (list 1 2) (list 3 4)))x((1 2) ...

sicp 2.26

    博客分类:
  • SICP
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 following expressions:     (append x y)(cons x y)(list x y)   求值结果分别是: (append x y)->(1 2 ...
Global site tag (gtag.js) - Google Analytics