Skip to content

Instantly share code, notes, and snippets.

@m039
Created February 3, 2012 10:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m039/1729643 to your computer and use it in GitHub Desktop.
Save m039/1729643 to your computer and use it in GitHub Desktop.
sicp exercise
;; 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