SICP-1.2.1节练习
SICP-1.2.3节练习

SICP-1.2.2节练习

lispor posted @ Feb 16, 2011 12:06:47 PM in Scheme with tags SICP , 2027 阅读

练习 1.11 - 1.13

 
练习 1.11:
A function f is defined by the rule that f(n) = n if n<3 and
f(n) = f(n - 1) + 2f(n - 2) + 3f(n - 3) if n>= 3. Write a procedure that computes f
by means of a recursive process. Write a procedure that computes f by means of an
iterative process.
我的解答:
递归计算过程:
(define (f n)
  (if (< n 3)
      n
      (+ (f (- n 1))
         (* 2 (f (- n 2)))
         (* 3 (f (- n 3))))))

迭代计算过程:
(define (f n)
  (define (iter a b c count)
         (if (= count 0)
             c
             (iter (+ a (* 2 b) (* 3 c)) a b (- count 1))))
  (iter 2 1 0 n))
 
练习 1.12:
The following pattern of numbers is called Pascal's triangle.
        1
      1   1
    1   2   1
  1   3   3   1
1   4   6   4   1
The numbers at the edge of the triangle are all 1, and each number inside the triangle
is the sum of the two numbers above it. Write a procedure that computes elements of
Pascal's triangle by means of a recursive process.
 
我的解答:
(define (pascal row col)
  (if (or (= col 1) (= row col))
           1
           (+ (pascal (- row 1) col)
              (pascal (- row 1) (- col 1)))))
 
练习 1.13:
我没证明出来,在网上搜的:http://pro.panxingzhi.net/wp/?p=519
答案如下:
 

 

Avatar_small
krfantasy 说:
Feb 22, 2011 02:04:57 PM

刚刚开始看SICP,1.11写的也没写得像博主漂亮 blush

cleaning services du 说:
Feb 22, 2020 03:22:58 AM

Another the reason why people sometimes avoid a advertisement cleaning system is quite possibly not absolutely sure how often jointly have professional carpet cleaners done so they don't recognize how to go about choosing the right service regarding needs. Most of the time, they will just need to do experienced cleaning and once every few months to annually, depending at the harm on typically the carpet and know about traffic typically the carpets will become. However, if there can be pets, babies and big traffic, then vacuuming carpets every 90 days might be needed.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter