sicp

sicp sandbox.
git clone git://git.ricketyspace.net/sicp.git
Log | Files | Refs

commit da0a1a31adefbc72660af102383b09994a96b4c7
parent 15cbcf16248f799ccf351623b9f09c8d348ee084
Author: rsiddharth <rsiddharth@ninthfloor.org>
Date:   Sat,  2 Apr 2016 00:48:13 +0000

one/seven - Add new functions.

New functions:
  - good-enough-alt?
  - sqrt-iter-alt
  - sqrt-sicp-alt

Diffstat:
one/seven.scm | 18+++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/one/seven.scm b/one/seven.scm @@ -3,7 +3,10 @@ ;;; <https://creativecommons.org/licenses/by-sa/4.0/>. (define-module (one seven) - #:export (tolerances-and-sqrt)) + #:export (tolerances-and-sqrt + good-enough-alt? + sqrt-iter-alt + sqrt-sicp-alt)) (use-modules (one six)) @@ -28,3 +31,16 @@ (cons tolerance custom-sqrt) (cons (cons tolerance custom-sqrt) (tolerances-and-sqrt x (/ tolerance 10)))))) +;;; start excercise 1.1.7 +(define (good-enough-alt? guess prev-guess) + (< (abs (- guess prev-guess)) 0.001)) + +(define (sqrt-iter-alt guess prev-guess x) + (if (good-enough-alt? guess prev-guess) + guess + (sqrt-iter-alt (improve guess x) guess + x))) + +(define (sqrt-sicp-alt x) + (sqrt-iter-alt 1.0 2.0 x)) +;;;; end excercise 1.1.7