Skip to content

Instantly share code, notes, and snippets.

@zard1989
Created November 29, 2009 13:39
Show Gist options
  • Select an option

  • Save zard1989/244911 to your computer and use it in GitHub Desktop.

Select an option

Save zard1989/244911 to your computer and use it in GitHub Desktop.
#!/usr/bin/guile -s
!#
(define (sqrt x)
(define (good-enough? guess)
(< (abs (- guess (/ x guess))) .001))
(define (improve guess)
(/ (+ guess (/ x guess)) 2))
(define (try guess)
(if (good-enough? guess)
guess
(try (improve guess))))
(try 1.0))
(display (sqrt 3))
(newline)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment