SICP 1.17 答案

看来书上的注释做出来了,效仿Russian peasant multiplication算法
(define (even? n)
  (= (remainder n 2) 0))

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

(define (double n)
  (* n 2))

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

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