Hatena::Groupcsnagoya-sicp

gabuchanの日記

2008-11-10

問題1.17

| 16:03

対数的ステップ数の乗算手続き。

(define (double x) (* x 2))
(define (halve x) (/ x 2))
(define (mul x y)
  (cond [(= y 0) 0]
        [(even? y) (double (mul x (halve y)))]
        [else (+ x (mul x (- y 1)))]))