Add 1.18
This commit is contained in:
parent
9de52ba145
commit
75bce812b1
|
@ -0,0 +1,28 @@
|
|||
(define (divide a b)
|
||||
(define (iter a b product)
|
||||
(cond ((= a 0) product)
|
||||
((< a 0) (- product 1))
|
||||
(else (iter (- a b) b (+ product 1)))))
|
||||
|
||||
(iter a b 0))
|
||||
; divide
|
||||
|
||||
(define (halve a)
|
||||
(divide a 2))
|
||||
|
||||
(define (double a)
|
||||
(+ a a))
|
||||
|
||||
(define (multiply a b)
|
||||
(define (iter a b product)
|
||||
(cond ((= a 1) (+ product b))
|
||||
((even? a) (iter (halve a) (double b) product))
|
||||
(else (iter (halve a) (double b) (+ product b)))))
|
||||
|
||||
(iter a b 0))
|
||||
; multiply
|
||||
|
||||
|
||||
(multiply 132 555)
|
||||
(multiply 32 2)
|
||||
(multiply 33 1)
|
Loading…
Reference in New Issue