in reply to Primes. Again.

johngg: Your vector solution works, but it doesn't remember between function calls the primes it's found, and it must be doing something odd, since calling it for a large number like 234223345333 gives the message:
# Assigning to negative offset in vec.
Calling it for a somewhat smaller number like 234223345 just makes it run practically forever.

EDIT: Never mind, I see the problem. You have to store a bit for each number that could potentially be a prime, so when the max number is extremely large, you apparently go out of bounds. Plus, hits on numbers that have already been punched out increase significantly after the first few primes, and I imagine it would be more efficient to pick some point after which to switch from skip counting to modulo testing.

Replies are listed 'Best First'.
Re^2: Primes. Again.
by johngg (Canon) on Apr 26, 2006 at 22:35 UTC
    It was not really meant to be a heavy duty prime number finder but something compatible with my rather meagre mathematical skills. And after all, Eratosthenes never had to worry about going out of bounds in 250BC :-) On my ancient hardware I don't ask it to go beyond 10000000 as I don't have all day while it fills in all the multiples of 2 etc.

    FWIW, I am still trying to get my head around your method. I downloaded and ran it and was very impressed with it's speed on a 250MHz UltraSPARC, but I don't quite understand it yet. I'll get there eventually.

    Cheers,

    JohnGG