Created
October 26, 2010 19:05
-
-
Save gar/647564 to your computer and use it in GitHub Desktop.
exercise1.8.rkt
This file contains 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
; SICP Exercise 1.8 | |
#lang racket | |
(define (cube-root x) | |
(define (square y) (* y y)) | |
(define (good-enough? guess) | |
(< (abs (- (square guess) x)) 0.001)) | |
(define (improve guess) | |
(/ (+ (square (/ guess x)) (* 2 guess))) 3) | |
(define (cube-root-iter guess) | |
(if (good-enough? guess) | |
guess | |
(cube-root-iter (improve guess)))) | |
(cube-root-iter 1.0)) | |
; TEST CODE | |
(cube-root 9) | |
(cube-root 81) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment