Created
October 27, 2014 14:53
-
-
Save paveljurca/58b7ce9fca8627c53a99 to your computer and use it in GitHub Desktop.
$> for a in `seq 1 100`; do if $( perl is_prime.pl $a ); then echo $a; fi; done
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use POSIX; | |
exit 2 unless &is_prime(pop @ARGV); | |
sub is_prime { | |
my $num = shift || 0; | |
return if $num<2 | |
|| ($num%2==0 && $num>2) | |
|| floor($num)<$num; | |
for (my $i=3; $i<=sqrt($num); $i+=2) { | |
return if $num % $i == 0; | |
} | |
1;#true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment