Created
May 12, 2016 08:34
-
-
Save 53ningen/7834890f6c1fef99bc08a18ca754a134 to your computer and use it in GitHub Desktop.
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
; 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