summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrsiddharth <s@ricketyspace.net>2016-06-25 18:31:36 +0000
committerrsiddharth <s@ricketyspace.net>2016-06-25 18:31:36 +0000
commite63ca8e496f7a4e34d88f8ef94574783cb62fa03 (patch)
tree1ec969f6daeb49b5c04d86a45238f0fe01dc4850
parent7324e84999431c3b6aaf151241696034b7301468 (diff)
sicp.org: tried ex. 1.9.
-rw-r--r--sicp.org40
1 files changed, 40 insertions, 0 deletions
diff --git a/sicp.org b/sicp.org
index b338700..db960ea 100644
--- a/sicp.org
+++ b/sicp.org
@@ -107,3 +107,43 @@ For a number as large as 1000000000, guile's =sqrt= function and
=sqrt-sicp-alt= returns 31622.776601683792, =sqrt-sicp= returns
31622.776601684047; =sqrt-sicp= being slightly more precise than the
other functions.
+*** 9
+**** recursive process
+
+#+BEGIN_SRC scheme
+(define (+ a b)
+ (if (= a 0)
+ b
+ (inc (+ dec a) b)))
+#+END_SRC
+
+#+BEGIN_SRC
+(+ 4 5) ----+
+(inc (+ 3 5)) |----+
+(inc (inc (+ 2 5))) |------+
+(inc (inc (inc (+ 1 5)))) |------+
+(inc (inc (inc (inc (+ 0 5))))) |
+(inc (inc (inc (inc 5)))) +-------+
+(inc (inc (inc 6))) +-----|
+(inc (inc 7)) +-----|
+(inc 8) +-----|
+9 <-----|
+#+END_SRC
+
+**** iterative process
+
+#+BEGIN_SRC scheme
+(define (+ a b)
+ (if (= a 0)
+ b
+ (+ (dec a) (inc b))))
+#+END_SRC
+
+#+BEGIN_SRC
+(+ 4 5 --+
+(+ 3 6) |
+(+ 2 7) |
+(+ 1 8) |
+(+ 0 9) |
+9 <------+
+#+END_SRC