-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1.37.rkt
39 lines (32 loc) · 879 Bytes
/
1.37.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#lang planet neil/sicp
(define tolerance 0.00001)
(define (fix-point f first-guess)
(define (close-enough? v1 v2)
(< (abs (- v1 v2)) tolerance))
(define (try guess)
(display guess)
(newline)
(let ((next (f guess)))
(if (close-enough? guess next)
next
(try next))))
(try first-guess))
(define (connect d n st en)
(if (= st en)
(/ (n st) (d st))
(/ (n st) (+ (d st) (connect d n (+ st 1) en)))))
(define (cont-frac n d k)
(define (iter x )
(if (= x k )
(/ (n k) (d k))
(/ (n x) (+ (d x)(iter (+ x 1))))))
(iter 1))
(define (cont-frac2 n d k)
(define (iter x result)
(if (= x 1)
result
(iter (- x 1)
(/ (n (- x 1))
(+ (d (- x 1)) result)))))
(iter k (/ (n k) (d k))))
(cont-frac2 (lambda (i) 1.0) (lambda (i) 1.0) 1000)