(defn sieve [potentials primes] ; stackoverflow.com/q/2946764/849891
(if-let [p (first potentials)]
(if (> (* p p) (last potentials))
(concat primes potentials)
(recur (filter (fn [n] (not= (mod n p) 0)) potentials)
primes))
(print ( (fn [s] [(count s),(last s)]) (sieve (range 2 160000) [])))
; (print (sieve (range 2 128) []))
; 30th prime: 113^2=12769 31st prime: 127^2=16129 1862nd prime: 15991
; 14,683rd: 159979 below 160,000 -- 1.17s (w/ doall: 1.23s)
; (just 78 primes below 400)
KGRlZm4gc2lldmUgW3BvdGVudGlhbHMgcHJpbWVzXSAgICA7IHN0YWNrb3ZlcmZsb3cuY29tL3EvMjk0Njc2NC84NDk4OTEKICAoaWYtbGV0IFtwIChmaXJzdCBwb3RlbnRpYWxzKV0KICAgICAgKGlmICg+ICgqIHAgcCkgKGxhc3QgcG90ZW50aWFscykpCiAgICAgICAgKGNvbmNhdCBwcmltZXMgcG90ZW50aWFscykKICAgICAgICAocmVjdXIgKGZpbHRlciAoZm4gW25dIChub3Q9IChtb2QgbiBwKSAwKSkgcG90ZW50aWFscykKICAgICAgICAgICAgICAgKGNvbmogcHJpbWVzIHApKSkKICAgIHByaW1lcykpCgoocHJpbnQgKCAoZm4gW3NdIFsoY291bnQgcyksKGxhc3QgcyldKSAoc2lldmUgKHJhbmdlIDIgMTYwMDAwKSBbXSkpKSAKCjsgKHByaW50ICAoc2lldmUgKHJhbmdlIDIgMTI4KSBbXSkpICAKCjsgMzB0aCBwcmltZTogMTEzXjI9MTI3NjkgIDMxc3QgcHJpbWU6IDEyN14yPTE2MTI5ICAgMTg2Mm5kIHByaW1lOiAxNTk5MQoKOyAxNCw2ODNyZDogMTU5OTc5ICAgYmVsb3cgMTYwLDAwMCAgIC0tICAxLjE3cyAody8gZG9hbGw6IDEuMjNzKQoKOyAgKGp1c3QgNzggcHJpbWVzIGJlbG93IDQwMCk=