405
备注:
|
850
|
删除的内容标记成这样。 | 加入的内容标记成这样。 |
行号 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
(define (factorial n) (if (= n 1) 1 (* n (factorial (- n 1)))))
1 factorial = lambda n: 1 if n==1 else n*factorial(n-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)))
2. Tree Recursion
3. Orders of Growth
4. Exponentiation
5. Greatest Common Divisors