Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: redmist's Diabolical Scheme for Prime Domination

by lhoward (Vicar)
on Aug 02, 2000 at 16:18 UTC ( [id://25708]=note: print w/replies, xml ) Need Help??


in reply to redmist's Diabolical Scheme for Prime Domination

Any "modern, efficient" method of finding primes is very advanced math intensive. Applied Cryptography has a good section of prime factoring and determining if a number is likely prime. Public key encryption systems based on large prime numbers (RSA) don't actually factor the large prime numbers. They generate numbers using a technique that ensures that they are probably prime. This is a great shortcut, but won't work for claiming a mathematical record like you are proposing as the number is only probably prime (extremely high certainty that it is prime, but still not %100 guaranteed).

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
    Thanks lhoward. I looked at the web page that you recommended and it helped me some with my thought on how I am going to approach the math in this project. As for your suggestion to use another, more mathematically inclined language, it's not an issue for me because this project is to learn Perl (and stick it to the man).

    redmist
    redmist.dyndns.org
    redmist@users.sourceforge.net
RE: Re: redmist's Diabolical Scheme for Prime Domination
by BlaisePascal (Monk) on Aug 02, 2000 at 18:17 UTC
    Here's my attempt at a Sieve of Eratothenes... I don't use grep that much, so I won't claim that this works...
    @numbers = (2 .. 1_000_000); @primes = ( ); while (my $prime = shift @numbers) { push @primes,$prime; @numbers = grep { ($_ % $prime) != 0 } @numbers; } print $primes;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://25708]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-19 23:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found