Initial commit.

This commit is contained in:
sergiotarxz 2021-04-19 20:47:54 +02:00
parent 7a60360b3d
commit 66ed70e1a1
Signed by: sergiotarxz
GPG Key ID: E5903508B6510AC2

23
prime.pl Normal file
View 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 ) . '.';