Re: The Genuine Sieve of Eratosthenes

2010-11-06 Thread Mark Engelberg
I like tinkering with prime sieve algorithms. Here's the fastest one I've come up with: (defn bit-sieve [n] (let [n (int n)] "Returns a vector of all primes from 2 to n (not including n)" (let [root (int (Math/round (Math/floor (Math/sqrt n] (loop [i (int 3) a (ja

Re: The Genuine Sieve of Eratosthenes

2010-11-06 Thread Ken Wesson
On Sat, Nov 6, 2010 at 5:50 PM, Juha Arpiainen wrote: > On Nov 6, 7:57 pm, Ken Wesson wrote: >>           (filter identity (map #(if %1 %2) (drop 2 sieve) (iterate inc 2))) > > Returning a lazy seq doesn't seem to make much sense here, > especially since (map ... (drop 2 sieve)) holds onto the >

Re: The Genuine Sieve of Eratosthenes

2010-11-06 Thread Juha Arpiainen
On Nov 6, 7:57 pm, Ken Wesson wrote: > Here's a Clojure sieve that works fine up to at least 50 > million and is reasonably fast (though the same algorithm implemented > in Java is 10x faster even with the type hints and primitive > arithmetic in the Clojure; not sure why). > > (defn primes-to [n]

Re: The Genuine Sieve of Eratosthenes

2010-11-06 Thread Ken Wesson
On Sat, Nov 6, 2010 at 11:28 AM, thattommyhall wrote: > Hey, > > I read http://www.cs.hmc.edu/~oneill/papers/Sieve-JFP.pdf a while ago > and noticed you had referenced the paper and implemented the naive > algorithm in contrib and thought I could chip in and do the sieve for > you but get an error