diff options
| -rwxr-xr-x | challenge-198/spazm/perl/ch-2.pl | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/challenge-198/spazm/perl/ch-2.pl b/challenge-198/spazm/perl/ch-2.pl new file mode 100755 index 0000000000..5b98bb812d --- /dev/null +++ b/challenge-198/spazm/perl/ch-2.pl @@ -0,0 +1,30 @@ +#!/usr/bin/env perl +use v5.34; + +use experimental qw(signatures); +use Math::Prime::Util qw(primes); + +=pod +Task 2: Prime Count +Submitted by: Mohammad S Anwar + +You are given an integer $n > 0. + +Write a script to print the count of primes less than $n. +=cut + +sub count_of_primes ($n) +{ + return scalar @{ primes($n) }; +} + +sub main +{ + for my $n ( 0, 1, 10, 15, 25 ) + { + printf( "there are %d primes less than %i\n", + count_of_primes($n), $n ); + } +} + +main(); |
