Solve 1.16
This commit is contained in:
parent
d49f5893ae
commit
ca2a636675
|
@ -1,19 +1,16 @@
|
||||||
; UNFINISHED
|
|
||||||
(define (sqr n)
|
(define (sqr n)
|
||||||
(* n n))
|
(* n n))
|
||||||
|
|
||||||
(define (fast-ext-iter number power product)
|
(define (fast-ext-iter number power product)
|
||||||
(cond ((= power 0) product)
|
(cond ((= power 0) product)
|
||||||
((even? power) (fast-ext-iter number
|
((even? power) (fast-ext-iter (sqr number)
|
||||||
(/ power 2)
|
(/ power 2)
|
||||||
(if (= product 1)
|
product))
|
||||||
(sqr number)
|
|
||||||
(sqr product))))
|
|
||||||
(else (fast-ext-iter number
|
(else (fast-ext-iter number
|
||||||
(- power 1)
|
(- power 1)
|
||||||
(* power product)))))
|
(* number product)))))
|
||||||
|
|
||||||
(define (fast-ext number power)
|
(define (fast-ext number power)
|
||||||
(fast-ext-iter number power 1))
|
(fast-ext-iter number power 1))
|
||||||
|
|
||||||
(fast-ext 2 8)
|
(fast-ext 2 5)
|
Loading…
Reference in New Issue