Skip to content

Instantly share code, notes, and snippets.

@kouddy
Last active August 29, 2015 14:15
Show Gist options
  • Save kouddy/423ce590e6cf313ba519 to your computer and use it in GitHub Desktop.
Save kouddy/423ce590e6cf313ba519 to your computer and use it in GitHub Desktop.
(define (double a) (* a 2))
(define (halve a) (/ a 2))
(define (even? n) (= (remainder n 2) 0))
(define (fast-mult a b )
(fast-mult-iter 0 a b))
(define (fast-mult-iter a b n)
(cond ((= n 0) a)
((even? n) (fast-mult-iter a (double b) (halve n)))
(else (fast-mult-iter (+ a b) b (- n 1)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment