# SICP-1.2.2节练习

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

```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))```

```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)))))```  krfantasy 说:
Feb 22, 2011 02:04:57 PM 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. (输入验证码)
or Ctrl+Enter