Skip to content

Instantly share code, notes, and snippets.

@yao2030
Created December 7, 2012 02:23
Show Gist options
  • Save yao2030/4230233 to your computer and use it in GitHub Desktop.
Save yao2030/4230233 to your computer and use it in GitHub Desktop.
(define (cont-frac n d k)
(define (cont-help i result)
(if (= i 0)
result
(cont-help (- i 1) (/ (n i) (+ (d i) result)))))
(cont-help k 0.0))
(cont-frac (lambda (i) 1.0) (lambda (i) 1.0) 100)
;; A so-called k-term finite continued fraction
;; gives the value of the gold ratio
(define (cont-fact n d k)
(define (cont-re i)
(if (> i k)
0
(/ (n i) (+ (d i) (cont-re (+ i 1))))))
(cont-re 1))
@yao2030
Copy link
Author

yao2030 commented Dec 7, 2012

Exercise 1.38 sicp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment