Created
December 9, 2011 21:34
-
-
Save k4rtik/1453401 to your computer and use it in GitHub Desktop.
My first scheme program, after watching the first HP SICP class video - June 28, 2011
This file contains 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 (sqrt2 x) | |
(define (square num) | |
(* num num)) | |
(define (average a1 a2) | |
(/ (+ a1 a2) 2)) | |
(define (improve guess) | |
(average guess (/ x guess))) | |
(define (good-enough? guess) | |
(< (abs (- (square guess) x)) | |
.000000001)) | |
(define (try guess) | |
(if (good-enough? guess) | |
guess | |
(try (improve guess)))) | |
(try 1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment