版本3和4间的区别
于2007-04-16 11:05:20修订的的版本3
大小: 405
编辑: czk
备注:
于2007-04-16 11:11:06修订的的版本4
大小: 850
编辑: czk
备注:
删除的内容标记成这样。 加入的内容标记成这样。
行号 11: 行号 11:
 1. {{{
(define (factorial n)
  (fact-iter 1 1 n))

(define (fact-iter product counter max-count)
  (if (> counter max-count)
      product
      (fact-iter (* counter product)
                 (+ counter 1)
                 max-count)))
}}}{{{#!python
fatorial = lambda n: fact_iter(1, 1, n)
fact_iter = lambda product, counter, max_count: product if counter > max_count else fact_iter(counter*product, counter +1, max_count)
}}}

Procedures and the Processes They Generate

1. Linear Recursion and Iteration

  1. (define (factorial n)
      (if (= n 1)
          1
          (* n (factorial (- n 1)))))
       1 factorial = lambda n: 1 if n==1 else n*factorial(n-1)
    
  2. (define (factorial n)
      (fact-iter 1 1 n))
    
    (define (fact-iter product counter max-count)
      (if (> counter max-count)
          product
          (fact-iter (* counter product)
                     (+ counter 1)
                     max-count)))
       1 fatorial = lambda n: fact_iter(1, 1, n)
       2 fact_iter = lambda product, counter, max_count: product if counter > max_count else fact_iter(counter*product, counter +1, max_count)
    

2. Tree Recursion

3. Orders of Growth

4. Exponentiation

5. Greatest Common Divisors

6. Example: Testing for Primality

SICP的Python实现/SICP的Python实现1.2 (2008-02-23 15:36:44由localhost编辑)

ch3n2k.com | Copyright (c) 2004-2020 czk.