Permalink
Browse files

1.17

  • Loading branch information...
1 parent bcac6e3 commit da5f88405f34ebcd8e05b620c934ec8560b66850 @knaveofdiamonds committed Feb 27, 2012
Showing with 15 additions and 1 deletion.
  1. +15 −1 1.2.scm
View
16 1.2.scm
@@ -167,4 +167,18 @@
(if (even? n)
(fast-expt-impl b (/ n 2) (* a (square b)))
(* b (fast-expt-impl b (/ (- n 1) 2) (* a (square b)))))))
- (fast-expt-impl b n 1))
+ (fast-expt-impl b n 1))
+
+;; 1.17
+
+(define (halve n)
+ (/ n 2))
+
+(define (double n)
+ (* n 2))
+
+(define (fast-mult a b)
+ (cond ((or (= a 0) (= b 0)) 0)
+ ((= b 1) a)
+ ((even? b) (double (fast-mult a (halve b))))
+ (else (+ a (fast-mult a (- b 1))))))

0 comments on commit da5f884

Please sign in to comment.