diff options
| author | Lubos Kolouch <lubos@kolouch.net> | 2022-02-26 13:21:48 +0100 |
|---|---|---|
| committer | Lubos Kolouch <lubos@kolouch.net> | 2022-02-26 13:21:48 +0100 |
| commit | 63c9bfd057090abb8146085c0e711298004a7f48 (patch) | |
| tree | 99e1e24aac5829d979d93ee5bef17652be6d6576 | |
| parent | f5ef44c5be4ea6d4e3137014aa5788236eab4b6d (diff) | |
| download | perlweeklychallenge-club-63c9bfd057090abb8146085c0e711298004a7f48.tar.gz perlweeklychallenge-club-63c9bfd057090abb8146085c0e711298004a7f48.tar.bz2 perlweeklychallenge-club-63c9bfd057090abb8146085c0e711298004a7f48.zip | |
feat(challenge-153/lubos-kolouch/php/ch-2.php): Challenge 153 Task 2 PHP LK
| -rw-r--r-- | challenge-153/lubos-kolouch/php/ch-2.php | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/challenge-153/lubos-kolouch/php/ch-2.php b/challenge-153/lubos-kolouch/php/ch-2.php new file mode 100644 index 0000000000..d7ab361c9f --- /dev/null +++ b/challenge-153/lubos-kolouch/php/ch-2.php @@ -0,0 +1,34 @@ +<?php + +function calculate_factorial(int $what){ + + $fact = 1; + + foreach (range(1, $what) as $i) { + $fact *= $i; + } + + return $fact; +} + + +function get_factorions_sum(int $what){ + + $my_sum = 0; + foreach (str_split($what) as $i) { + $my_sum += calculate_factorial($i); + } + + return $my_sum; +} + + +function is_equal(int $what){ + return $what == get_factorions_sum($what); +} + + +is_equal(145) == 1 or throw new Exception("Test 1 failed"); +is_equal(123) == 0 or throw new Exception("Test 2 failed"); + +?> |
