Created
August 23, 2017 09:50
-
-
Save dcb9/e5a7ec01b6fac74258a37a58e5103e04 to your computer and use it in GitHub Desktop.
sicp-1.7 created by dcb9 - https://repl.it/KVr5/1
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 (average x) (/ x 2)) | |
(define (square x) (* x x)) | |
(define (abs x) (if (< x 0) (- 0 x) x)) | |
; (define (good-enough? guess x) | |
; (if (< (abs (- (square guess) x)) 0.00000000001) | |
; #t | |
; #f)) | |
(define (good-enough? guess x) | |
(if (< (/ (abs (- guess (improve guess x))) guess) 0.00000000001) | |
#t | |
#f)) | |
(define (improve guess x) | |
(average (+ (/ x guess) guess))) | |
(define (sqrt-iter guess x) | |
(if (good-enough? guess x) | |
guess | |
(sqrt-iter (improve guess x) x))) | |
(define (sqrt x) | |
(sqrt-iter 1.0 x)) | |
(sqrt 16) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment