To be noted: the drawing in exercise 1.14 is unfinished. I did it in a notebook, but haven't yet had the time to put it in a txt file.
10 lines
252 B
Scheme
10 lines
252 B
Scheme
#lang sicp
|
|
|
|
(define (double x) (* 2 x))
|
|
(define (halve x) (/ x 2))
|
|
(define (*aux a b acc)
|
|
(cond ((= b 0) acc)
|
|
((even? b) (*aux (double a) (halve b) acc))
|
|
(else (*aux a (- b 1) (+ acc a)))))
|
|
(define (fast-mul a b)
|
|
(*aux a b 0))
|