diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-02-23 19:57:09 +0000 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-02-23 19:57:09 +0000 |
| commit | e5f746f7287eafbea87a8f545c2266e01c378323 (patch) | |
| tree | 2fcb26bc29a962b1263c0c9172613fdf2d6d4795 /challenge-153/mohammad-anwar/perl/ch-2.pl | |
| parent | ae7f393c5d3c608afad01cc6e68012da06797b20 (diff) | |
| download | perlweeklychallenge-club-e5f746f7287eafbea87a8f545c2266e01c378323.tar.gz perlweeklychallenge-club-e5f746f7287eafbea87a8f545c2266e01c378323.tar.bz2 perlweeklychallenge-club-e5f746f7287eafbea87a8f545c2266e01c378323.zip | |
- Added Perl solutions to the week 153.
Diffstat (limited to 'challenge-153/mohammad-anwar/perl/ch-2.pl')
| -rw-r--r-- | challenge-153/mohammad-anwar/perl/ch-2.pl | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/challenge-153/mohammad-anwar/perl/ch-2.pl b/challenge-153/mohammad-anwar/perl/ch-2.pl new file mode 100644 index 0000000000..3127981a78 --- /dev/null +++ b/challenge-153/mohammad-anwar/perl/ch-2.pl @@ -0,0 +1,41 @@ +#!/usr/bin/perl + +=head1 + +Week 153: + + https://theweeklychallenge.org/blog/perl-weekly-challenge-153 + +Task #2: Factorions + + You are given an integer, $n. + + Write a script to figure out if the given integer is factorion. + +=cut + +use strict; +use warnings; +use Test::More; + +is(factorion(145), 1, 'Example 1'); +is(factorion(123), 0, 'Example 2'); + +done_testing; + +# +# +# METHOD + +sub factorion { + my ($n) = @_; + + my $s = 0; + foreach my $_n (split //, $n) { + my $f = 1; + $f = $f * $_ for 1..$_n; + $s = $s + $f; + } + + return ($s == $n)?(1):(0); +} |
