Skip to content

Instantly share code, notes, and snippets.

@k4rtik
Created December 9, 2011 21:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save k4rtik/1453401 to your computer and use it in GitHub Desktop.
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
(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