Skip to content

Instantly share code, notes, and snippets.

@53ningen
Created May 12, 2016 08:34
Show Gist options
  • Save 53ningen/7834890f6c1fef99bc08a18ca754a134 to your computer and use it in GitHub Desktop.
Save 53ningen/7834890f6c1fef99bc08a18ca754a134 to your computer and use it in GitHub Desktop.
; your code goes here
(define (square x) (* x x))
(define (sum-of-square x y) (+ (square x) (square y)))
(define (q13 x y z) (cond
((and (>= y x) (>= z x)) (sum-of-square y z))
((and (>= x y) (>= z y)) (sum-of-square x z))
(else (sum-of-square x y))
))
(q13 1 2 3)
(define (sqrt x) (* x x))
(define (average x y)
(/ (+ x y) 2))
(define (improve guess x)
(average guess (/ x guess )))
(define (good-enough? guess x)
(< (abs (- (square guess) x)) 0.001))
(define (sqrt-iter guess x)
(if (good-enough? guess x)
guess
(sqrt-iter (improve guess x) x)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment