in reply to Finding the next larger prime.
This may not be exactly what you want, but it should do the trick.
sub next_prime_iterator { my $num = shift; do { $num++ } until is_prime($num); return $num; } sub is_prime { my $guess = shift; return 1 if $guess == 2; return unless $guess > 2 and $guess % 2; my $max = 1 + int $guess ** .5; for ( my $divisor = 3; $divisor < $max; $divisor += 2 ) { return unless $guess % $divisor; } return 1; }
Cheers,
Ovid
New address of my CGI Course.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Finding the next larger prime. (improve)
by tye (Sage) on Oct 30, 2003 at 17:17 UTC |