Instantly share code, notes, and snippets.

Embed
What would you like to do?
(ns cf
(:require [clojure.math.numeric-tower :as nt]))
(defn- step [x-2 x-1 [a & as]]
(when a
(let [x (+ (* a x-1) x-2)]
(cons x (lazy-seq (step x-1 x as))))))
(defn convergents [as]
(let [c (fn c [[h & hs] [k & ks]]
(when (and h k)
(cons (/ h k) (lazy-seq (c hs ks)))))]
(c (step 0 1 as) (step 1 0 as))))
(->> 1 repeat convergents (take 20) println)
(println (convergents '(3 7 15 1 292 1 1 1)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment