Pumping the Primes
bit-player.org
bit-player.org
(let [gcd (fn [x y]
(if (pos? y)
(recur y (mod x y))
x))]
(->> [2 7 1]
(iterate (fn [[n a]]
(let [g (gcd n a)]
[(inc n) (+ a g) g])))
(filter (comp #(< 1 %) last))
(take 20)))
I would format it better if I knew how to.Anyway, the last element of each vector (that is, the g) in the resulting sequence is always a prime.
The first twenty elements are returned in 4msecs. The first 200 are still running (> 2 hours already).