[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Prime Numbers



On Mon, Aug 16, 1999 at 07:37:31AM -0400, Bill Jones wrote:
> > (Does it do the first 1000 primes *correctly*?  If not, then the time to
> > produce the first 1000 primes is infinite, and speeding it up would be done
> > first by making it correct.)
> >
> 
> Are you suggesting they are not correct???
> 
> >
> >>my $idx;
> >>
> >>while (++$_) {
> >> print "",
> >>  (((1x $_) !~ /^(11+)\1+$/) ? "Yes $_ is prime; found " .++$idx." numbers"
> >>: next ),
> >> "\n";
> >>}
> 
> 
> I have verified that the first 1,000 are prime.

Except for 1, which is neither prime nor composite.


my $idx;
$_ = 1;

while (++$_) {
  next if (1 x $_) =~ /^(11+)\1+$/;
  print "Yes $_ is prime; found " . ++$idx . " numbers\n";
}

Ronald

===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org