Skip to content

Commit

Permalink
adding ex1-18
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Matuzak committed Jul 11, 2010
1 parent 4387fda commit 74ed777
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions chapter1/ex1-18.ss
@@ -0,0 +1,14 @@
(define (double a)
(+ a a))

(define (halve a)
(/ a 2))

(define (new-* a b)
(new-*-iter 0 a b))

(define (new-*-iter p a counter)
(cond ((= counter 0) p)
((even? counter)
(new-*-iter p (double a) (halve counter)))
(else (new-*-iter (+ p a) a (- counter 1)))))

0 comments on commit 74ed777

Please sign in to comment.