12 lines
259 B
Racket
12 lines
259 B
Racket
#lang sicp
|
|
|
|
(define (fast-exp b n)
|
|
;(define (even?)); already defined by racket
|
|
(define (actual b n a)
|
|
(cond
|
|
((= n 0) a)
|
|
;((= n 1) a)
|
|
((even? n) (actual (* b b) (/ n 2) a))
|
|
(else (actual b (- n 1) (* a b)))))
|
|
(actual b n 1))
|