Initial commit.
This commit is contained in:
parent
7a60360b3d
commit
66ed70e1a1
23
prime.pl
Normal file
23
prime.pl
Normal file
@ -0,0 +1,23 @@
|
||||
use 5.30.3;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
die "No argument received." unless scalar @ARGV;
|
||||
my $n = $ARGV[0];
|
||||
die "That does not look like like an integer positive number." unless $n =~ /^\d+$/;
|
||||
|
||||
my @prime_list;
|
||||
for my $current_number ( 2 .. $n ) {
|
||||
my $is_prime = 1;
|
||||
for my $prime ( @prime_list ) {
|
||||
unless ($current_number % $prime) {
|
||||
$is_prime = 0;
|
||||
last;
|
||||
}
|
||||
}
|
||||
push @prime_list, $current_number if $is_prime;
|
||||
}
|
||||
|
||||
say 'Your primes are: ' . (join ', ', @prime_list) . '.';
|
||||
say 'The number of primes is: ' . ( scalar @prime_list ) . '.';
|
Loading…
Reference in New Issue
Block a user