Skip to content

Instantly share code, notes, and snippets.

@davorg
Created April 20, 2013 16:53
Show Gist options
  • Save davorg/5426617 to your computer and use it in GitHub Desktop.
Save davorg/5426617 to your computer and use it in GitHub Desktop.
Simple prime checker
#!/usr/bin/perl
use warnings;
use strict;
while(<DATA>) {
chomp;
my $flag = 1;
foreach my $i (2 .. sqrt($_)) {
unless ($_ % $i) {
$flag = 0;
last;
}
}
print "Number $_ ";
if ($flag) {
print "prime";
} else {
print "not prime";
}
print "\n";
}
__END__
0
2
4
5
6
7
8
9
10
11
14
17
18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment