Solve 1.16

This commit is contained in:
NaiJi ✨ 2020-08-11 01:32:48 +03:00
parent d49f5893ae
commit ca2a636675
1 changed files with 4 additions and 7 deletions

View File

@ -1,19 +1,16 @@
; UNFINISHED
(define (sqr n)
(* n n))
(define (fast-ext-iter number power product)
(cond ((= power 0) product)
((even? power) (fast-ext-iter number
((even? power) (fast-ext-iter (sqr number)
(/ power 2)
(if (= product 1)
(sqr number)
(sqr product))))
product))
(else (fast-ext-iter number
(- power 1)
(* power product)))))
(* number product)))))
(define (fast-ext number power)
(fast-ext-iter number power 1))
(fast-ext 2 8)
(fast-ext 2 5)