in reply to redmist's Diabolical Scheme for Prime Domination
There are many simple prime number algorightms around, unfortunately the simple ones aren't efficient. The Sieve of Erastothenes is a classic example. I do not know of any perl modules that explicitly implement prime number type functionality. Below is a simple and extermely inefficient is_prime function.
sub is_prime{ my $n=shift; return 0 if($n != int($n)); my $m=sqrt($n); for(my $c=2;$c<=$m;$c++){ return 0 if($n/$c == int($n/$c)); } return 1; }
Any way you slice it, I don't think Perl is the best language for a high performance prime number analyzer. Your best bet would be to find a language designed explicitly for doing large number math if you seriously want to go after a "largest prime number" record.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Re: redmist's Diabolical Scheme for Prime Domination
by redmist (Deacon) on Aug 02, 2000 at 16:49 UTC | |
|
RE: Re: redmist's Diabolical Scheme for Prime Domination
by BlaisePascal (Monk) on Aug 02, 2000 at 18:17 UTC |