2 (:use [sicp utils ex1_37]
3 [clojure.contrib test-is]))
5 (defn gen-sequence [len]
6 (let [l (+ 1 (int (/ len 3)))
7 s1 (map #(* % 2) (range 1 (inc l)))
8 s2 (map (fn [_] 1) (range 1 (inc l)))]
9 (concat [0 1] (interleave s1 s2 s2))))
10 ;; we concat [0 1] because nth sequences are indexed from 0
14 (* (/ (+ k 1) 3) 2) ;; ((k+1)/3)*2
18 (defn e-approximation [len]
20 (cont-frac (fn [k] 1.0)
25 user> (e-approximation 10)
27 user> (e-approximation 20)
29 user> (e-approximation 40)
31 user> (e-approximation 50)
33 user> (e-approximation 60)
35 user> (e-approximation 100)