sicp-exercises/ex-1-16.rkt
2025-01-02 17:49:30 +03:00

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))