Skip to content

Instantly share code, notes, and snippets.

@kouddy
Created February 22, 2015 15:03
Show Gist options
  • Save kouddy/5ecf301eb437581c8223 to your computer and use it in GitHub Desktop.
Save kouddy/5ecf301eb437581c8223 to your computer and use it in GitHub Desktop.
(define (square x) (* x x))
(define (even? n)
(= (remainder n 2) 0))
(define (fast-expt b n)
(fast-expt-iter 1 b n))
(define (fast-expt-iter a b n)
(cond ((= n 0) a)
((even? n) (fast-expt-iter a (square b) (/ n 2)))
(else (fast-expt-iter (* a b) b (- n 1)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment