Skip to content

Instantly share code, notes, and snippets.

@littleredcomputer
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save littleredcomputer/cee99c791cadf40e35c3 to your computer and use it in GitHub Desktop.
Save littleredcomputer/cee99c791cadf40e35c3 to your computer and use it in GitHub Desktop.
(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