Last active
August 29, 2015 14:15
-
-
Save kouddy/0199a09f23b098f494bb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (square x) (* x x)) | |
(define (average x y) | |
(/ (+ x y) 2)) | |
(define (improve guess x) | |
(average guess (/ x guess))) | |
;;; Newly implemented guess | |
;;; Good enough when |guess - improved-guess|/guess < 0.001 (0.1%) | |
(define (good-enough? guess improved-guess x) | |
(< (/ (abs (- guess improved-guess)) guess) 0.001)) | |
(define (sqrt-iter guess x) | |
(if (good-enough? guess (improve guess x) x) | |
guess | |
(sqrt-iter (improve guess x) | |
x))) | |
(define (sqrt x) | |
(sqrt-iter 1.0 x)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment