diff options
| author | Lubos Kolouch <lubos@kolouch.net> | 2022-02-26 12:15:52 +0100 |
|---|---|---|
| committer | Lubos Kolouch <lubos@kolouch.net> | 2022-02-26 12:15:52 +0100 |
| commit | 32bc285d8a5f175aae30142ce0e7f1211af5a63e (patch) | |
| tree | 411c19b5a87203e6017cd2ec90d270762f0471a5 | |
| parent | f50d577c273c460cafc1ebf53d5ab117a44341a4 (diff) | |
| download | perlweeklychallenge-club-32bc285d8a5f175aae30142ce0e7f1211af5a63e.tar.gz perlweeklychallenge-club-32bc285d8a5f175aae30142ce0e7f1211af5a63e.tar.bz2 perlweeklychallenge-club-32bc285d8a5f175aae30142ce0e7f1211af5a63e.zip | |
feat(challenge-153/lubos-kolouch/perl/ch-2.pl): Challenge 153 Task 2 Perl LK
| -rw-r--r-- | challenge-153/lubos-kolouch/perl/ch-2.pl | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/challenge-153/lubos-kolouch/perl/ch-2.pl b/challenge-153/lubos-kolouch/perl/ch-2.pl new file mode 100644 index 0000000000..6911fdbe74 --- /dev/null +++ b/challenge-153/lubos-kolouch/perl/ch-2.pl @@ -0,0 +1,33 @@ +use strict; +use warnings; + + +sub calculate_factorial { + my $what = shift; + + my $fact = 1; + + $fact *= $_ for (1..$what); + + return $fact; +} + +sub get_factorions_sum { + my $what = shift; + + my $sum = 0; + + $sum += calculate_factorial($_) for (split //, $what); + return $sum; +} + + +sub is_equal { + my $what = shift; + return $what == get_factorions_sum($what); +} + +use Test::More; +is(is_equal(145), 1); +is(is_equal(123), ''); +done_testing; |
