in reply to Finding Primes
&gen_primes(eval(1 . '0' x 10));
The number 1-with-ten-zeros-after-it can be written as 10 ** 10.
foreach (@primes) { ... foreach (@primes) { ... } }
You can make a brute force search run faster by cutting off areas of the search space that you know can be skipped.
In this case, there are a number of ways you can shrink the search space; for example, next if ( $a > $b ); allows you to avoid checking twice for $a * $b and $b * $a, and next PRIMESCAN if ( length($a * $b) > 400; would let you stop testing a sequence when the numbers got too large.
Even with these tricks, brute-force isn't going to be an efficient approach, for the reasons discussed elsewhere.
last PRIMESCAN and print <<__FOUND__
This invokes "last" before "print" -- meaning that the print never gets invoked. You probably want print <<__FOUND__ and last PRIMESCAN.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Finding Primes
by Tommy (Chaplain) on Aug 14, 2003 at 01:53 UTC |