From e63ca8e496f7a4e34d88f8ef94574783cb62fa03 Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Sat, 25 Jun 2016 18:31:36 +0000 Subject: sicp.org: tried ex. 1.9. --- sicp.org | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) 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 -- cgit v1.2.3