Created
February 3, 2012 10:51
-
-
Save m039/1729643 to your computer and use it in GitHub Desktop.
sicp exercise
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Exercise 1.16 | |
(define (fast-expt-iter acc i n b) | |
(cond ((= n 0) acc) | |
((= i 0) (fast-expt-iter b 1 (- n 1) b)) | |
((= i 1) (fast-expt-iter (* b b) 2 (- n 1) b)) | |
((>= (- n i) 0) (fast-expt-iter (* acc acc) (+ i i) (- n i) b)) | |
(else (* acc (fast-expt-iter acc 0 n b))))) | |
(define (fast-expt b n) | |
(fast-expt-iter 1 0 n b)) | |
(fast-expt 2 10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment