Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Pumping the Primes (bit-player.org)
78 points by breadbox on Aug 19, 2015 | hide | past | favorite | 3 comments


For the clojure people:

  (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.


Regarding run time, you can see there is no free lunch:

The first twenty elements are returned in 4msecs. The first 200 are still running (> 2 hours already).


I looked up Matt Frank (mentioned in the article) and I see that he's now working in Finance. Surprise, surprise! :D




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: