Permalink
Browse files

1.20

  • Loading branch information...
1 parent aaaf3c0 commit acf276ceb2e54f27994f48398ad502309ed06cc8 @cosmin committed Feb 13, 2012
Showing with 16 additions and 0 deletions.
  1. +16 −0 exercise-1-20.ss
View
@@ -0,0 +1,16 @@
+(define (gcd a b)
+ (if (= b 0)
+ a
+ (gcd b (remainder a b))))
+
+;; applicative order => remainder is evaluated 4 times
+;; (gcd 206 40) =>
+;; (gcd 40 (remainder 206 40)) =>
+;; (gcd 6 (remainder 40 6)) =>
+;; (gcd 4 (remainder 6 4)) =>
+;; (gcd 2 (remainder 4 2)) =>
+;; 2
+
+;; normal order => remainder is evaluated 18 times
+;; this gets messy quickly, see the full explanation
+;; http://www.billthelizard.com/2010/01/sicp-exercise-120-gcd.html

0 comments on commit acf276c

Please sign in to comment.