SICP 1.18 答案

不太了解题目的意思,仅仅是把上面的算法改成迭代吗?
(define (even? n)
  (= (remainder n 2) 0))

(define (halve n)
  (if (even? n) (/ n 2)
      (/ (- n 1) 2)))

(define (double n)
  (+ n n))

(define (fast-multi a b)
  (fast-multi-iter 0 a b))

(define (fast-multi-iter r a b)
  (cond ((= a 0) r)
        ((even? a) (fast-multi-iter r (halve a) (double b)))
        (else (fast-multi-iter (+ r b) (halve a) (double b)))))

你可能感兴趣的:(算法,Scheme)