diff options
| author | Simon Miner <simon.miner@gmail.com> | 2020-08-03 13:46:29 -0400 |
|---|---|---|
| committer | Simon Miner <simon.miner@gmail.com> | 2020-08-03 13:46:29 -0400 |
| commit | 168c90ac5e83a1566a917223b83350cc0cdef55b (patch) | |
| tree | ab4aa1a3e93bb20f4308a7960afb8189630d29b2 | |
| parent | 94726265299352e69d053c5ef4f9b25b55b468db (diff) | |
| download | perlweeklychallenge-club-168c90ac5e83a1566a917223b83350cc0cdef55b.tar.gz perlweeklychallenge-club-168c90ac5e83a1566a917223b83350cc0cdef55b.tar.bz2 perlweeklychallenge-club-168c90ac5e83a1566a917223b83350cc0cdef55b.zip | |
Write ch-1.pl for task #! - trailing zeroes.
| -rwxr-xr-x | challenge-072/simon-miner/perl/ch-1.pl | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/challenge-072/simon-miner/perl/ch-1.pl b/challenge-072/simon-miner/perl/ch-1.pl new file mode 100755 index 0000000000..248cd2d04c --- /dev/null +++ b/challenge-072/simon-miner/perl/ch-1.pl @@ -0,0 +1,12 @@ +use strict; +use warnings; + +my $n = shift @ARGV; +die "Please specify a number between 1 and 10.\n" unless $n =~ m/^\d+$/ && $n <= 10; + +my $fact = 1; +$fact *= $_ for ( 1 .. $n ); +my ( $trailing_zeroes ) = ( $fact =~ m/(0+)$/ ); +my $trailing_zero_count = defined( $trailing_zeroes ) ? length( $trailing_zeroes ) : 0; + +print "$trailing_zero_count ($n! = $fact)\n"; |
