Last active
August 24, 2017 01:09
-
-
Save dcb9/646d2786a09429bf326812dbae212ed4 to your computer and use it in GitHub Desktop.
sicp-1.8 created by dcb9 - https://repl.it/KVqC/7
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
(define (square x) (* x x)) | |
(define (double x) (+ x x)) | |
(define (athird x) (/ x 3)) | |
(define (cube x) (* x x x)) | |
(define (abs x) (if (< x 0) (- 0 x) x)) | |
(define (good-enough? guess x) | |
(< (abs (- (cube guess) x)) 0.0000001)) | |
(define (improve guess x) | |
(athird (+ (/ x (square guess)) (double guess)))) | |
(define (cbrt-iter guess x) | |
(if (good-enough? guess x) | |
guess | |
(cbrt-iter (improve guess x) x))) | |
(define (cbrt x) | |
(cbrt-iter 1.0 x)) | |
(cbrt 9) | |
; (cbrt 64) | |
; (cbrt 27) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment