in reply to Prime list

Hello,
when i was writing Tk Tartaglia's triangle fun - Pascal's triangle fun i needed to check for primality and i found this thread with this fast solution; maybe you learn something from it

HtH
L*
There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Replies are listed 'Best First'.
Re^2: Prime list
by danaj (Friar) on Feb 12, 2015 at 17:19 UTC

    I would suggest actually looking at a sieve, for example the ones on RosettaCode. They are much faster than the trial division method you link to, albeit generating primes starting at two.

    For doing trial division, the skip-2-3 primality test from RosettaCode is twice as fast as the code you link to. Just wrap in something like: my @primes = grep { isprime($_) }  1..1000000;

    While the regex solution mentioned in another reply is super clever, it is also super not useful for the task once past toy sizes.