sicp-exs/sicp-ex-1.16.rkt

16 lines
463 B
Racket

(define (sqr n)
(* n n))
(define (fast-ext-iter number power product)
(cond ((= power 0) product)
((even? power) (fast-ext-iter (sqr number)
(/ power 2)
product))
(else (fast-ext-iter number
(- power 1)
(* number product)))))
(define (fast-ext number power)
(fast-ext-iter number power 1))
(fast-ext 2 5)