Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Michael Matuzak
committed
Jul 11, 2010
1 parent
4387fda
commit 74ed777
Showing
1 changed file
with
14 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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))))) |