;; The first three lines of this file were inserted by DrRacket. They record metadata
;; about the language level of this file in a form that our tools can easily process.
#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname heron) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f () #f)))
;; Number Number -> Number
;; guess is the current guess
(define better-guess
(lambda (x guess)
(/ (+ guess (/ x guess)) 2)))
;; Number Number -> Number
(define distance
(λ(a b)
(abs (- a b))))
(define a 4) ;; approximate the square root of x
(define guess-1 1) ;; initial guess
(define guess-2 (better-guess a guess-1))
(define guess-3 (better-guess a guess-2))
(define guess-4 (better-guess a guess-3))
(define guess-5 (better-guess a guess-4))
(define guess-6 (better-guess a guess-5))
(define guess-7 (better-guess a guess-6))
(define guess-8 (better-guess a guess-7))
(define guess-9 (better-guess a guess-8))
(define guess-10 (better-guess a guess-9))
;; Test the guesses
guess-1
guess-2
guess-3
guess-4
guess-5
guess-6
guess-7
guess-8
guess-9
guess-10