fork download
  1. (defn sieve [potentials primes] ; stackoverflow.com/q/2946764/849891
  2. (if-let [p (first potentials)]
  3. (if (> (* p p) (last potentials))
  4. (concat primes potentials)
  5. (recur (filter (fn [n] (not= (mod n p) 0)) potentials)
  6. (conj primes p)))
  7. primes))
  8.  
  9. (print ( (fn [s] [(count s),(last s)]) (sieve (range 2 160000) [])))
  10.  
  11. ; (print (sieve (range 2 128) []))
  12.  
  13. ; 30th prime: 113^2=12769 31st prime: 127^2=16129 1862nd prime: 15991
  14.  
  15. ; 14,683rd: 159979 below 160,000 -- 1.17s (w/ doall: 1.23s)
  16.  
  17. ; (just 78 primes below 400)
Success #stdin #stdout 1.17s 335552KB
stdin
Standard input is empty
stdout
[14683 159979]