in reply to Re: Math help: Finding Prime Numbers
in thread Math help: Finding Prime Numbers

Considering that lists of prime numbers are easily available, I'm not so sure whether a sieve beats reading them from disk.

Unless one is doing it for fun, as an exercise, to check the validity of the list, or to expand a list, there's no reason to write a program that generates prime numbers starting from 2. We promote people to reuse code and not reinvent the wheel. There's no reason to be different when it comes to data.

Replies are listed 'Best First'.
Re^3: Math help: Finding Prime Numbers
by syphilis (Archbishop) on Nov 13, 2006 at 10:39 UTC
    I'm not so sure whether a sieve beats reading them from disk

    Yep - a half-decent sieve does beat reading from disk ... unless it's a very short list that you're after.

    Cheers,
    Rob
    Update: Actually ... come to think about it ... a half-decent sieve might beat reading from disk, even if it is a very short list

      Ovid said:

      This is part of a larger set of code which is intended to be pure Perl, ...

      Can you write a "half descent sieve" in Perl?

      Also, how about if you want the 2e6 through 3e6 primes the first time you call and the 1e6 through 2e6 the second time?


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        I wasn't responding to Ovid. I was responding to Anonymous Monk's thoughts on sieving vs reading from disk - which I took to be of a more general nature (ie not in relation to just "pure perl").

        I honestly don't know whether a "pure perl" sieve would beat reading from disk. I might give it a whirl later today, if I get time. (Or has somebody else already done compararive benchmarking ?)

        Cheers,
        Rob