You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
19 lines
423 B
19 lines
423 B
(define (my-expt-recur b n) |
|
(if (= n 0) |
|
1 |
|
(* b (my-expt-recur b (- n 1))))) |
|
|
|
(define (my-expt-iter b n) |
|
(define (iter b n product) |
|
(if (= n 0) |
|
product |
|
(iter b |
|
(- n 1) |
|
(* b product)))) |
|
(iter b n 1)) |
|
|
|
(define (fast-expt b n) |
|
(define (square x) (* x x)) |
|
(cond ((= n 0) 1) |
|
((even? n) (square (fast-expt b (/ n 2)))) |
|
(else (* b (fast-expt b (- n 1))))))
|
|
|