summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2001-02-04 15:52:17 +0000
committerJim Meyering <jim@meyering.net>2001-02-04 15:52:17 +0000
commitff10610d6c58a02d354a74ff024ce90d69684c76 (patch)
tree78065aa47fb6cfbd213078e7d60ab319e2a8a75e
parent23d47fb4aab800da7f17a713581540dc04c9b04a (diff)
downloadcoreutils-ff10610d6c58a02d354a74ff024ce90d69684c76.tar.xz
(is_prime): Remove function.
-rwxr-xr-xsrc/wheel-gen.pl60
1 files changed, 26 insertions, 34 deletions
diff --git a/src/wheel-gen.pl b/src/wheel-gen.pl
index a944b91c5..ff8dc0e8a 100755
--- a/src/wheel-gen.pl
+++ b/src/wheel-gen.pl
@@ -6,7 +6,7 @@
use strict;
use Getopt::Long;
-(my $VERSION = '$Revision: 1.3 $ ') =~ tr/[0-9].//cd;
+(my $VERSION = '$Revision: 1.4 $ ') =~ tr/[0-9].//cd;
(my $program_name = $0) =~ s|.*/||;
my $debug = 0;
@@ -67,43 +67,35 @@ sub END
my $wheel_size = $ARGV[0];
- sub is_prime ($)
- {
- my ($n0) = @_;
- use integer;
-
- $n0 == 2
- and return 1;
-
- my $n = $n0;
- my $d = 2;
- my $w = 1;
- my $q;
- while (1)
- {
- $q = $n / $d;
- #print "q=$q n=$n d=$d\n";
- ($n == $q * $d)
- and return 0;
- $d += $w;
- $q < $d
- and last;
- $w = 2;
- }
- return 1;
- }
-
- my $prod = 2 * 3 * 5;
- my $last_prime = 2;
- my $i;
- for ($i = 3; $i < 2 * $prod; $i++)
+ my @primes = (2);
+ my $product = $primes[0];
+ my $n_primes = 1;
+ for (my $i = 3; ; $i += 2)
{
if (is_prime $i)
{
- print $i, ' ', $i - $last_prime, "\n";
- $last_prime = $i;
+ push @primes, $i;
+ $product *= $i;
+ ++$n_primes == $wheel_size
+ and last;
+ }
+ }
+
+ my $prev = 2;
+ for (my $i = 3; ; $i += 2)
+ while (1)
+ {
+ my $rel_prime = 1;
+ foreach my $d (@primes)
+ {
+ FIXME
+ }
+ if ($rel_prime)
+ {
+ print $i, ' ', $i - $prev, "\n";
+ $prev = $i;
- $prod < $i
+ $product < $i
and last;
}
}