Last active
August 29, 2015 14:14
-
-
Save littleredcomputer/cee99c791cadf40e35c3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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