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

[MacPerl] Prime Numbers [Was: pi, slightly off topic]



Way off topic:

The following determines if a number is prime (I got it from an Abby .sig a
while back; he makes the greatest one liners :)   However, it takes about 6
minutes to calculate the first 1,000 prime numbers -

my $idx;

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

Can anyone speed it up?
-Sneex-  :]

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