diff options
author | rsiddharth <rsiddharth@ninthfloor.org> | 2016-04-02 00:48:13 +0000 |
---|---|---|
committer | rsiddharth <rsiddharth@ninthfloor.org> | 2016-04-02 00:48:13 +0000 |
commit | da0a1a31adefbc72660af102383b09994a96b4c7 (patch) | |
tree | 5a62177fcbc275ec77c8e9b4fbcd3a1a909b63e6 | |
parent | 15cbcf16248f799ccf351623b9f09c8d348ee084 (diff) |
one/seven - Add new functions.
New functions:
- good-enough-alt?
- sqrt-iter-alt
- sqrt-sicp-alt
-rw-r--r-- | one/seven.scm | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/one/seven.scm b/one/seven.scm index 66e06d9..cc3c7b9 100644 --- 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 |