diff options
| -rw-r--r-- | challenge-149/abigail/perl/ch-1.pl | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/challenge-149/abigail/perl/ch-1.pl b/challenge-149/abigail/perl/ch-1.pl index ca72dbefbf..0f4127cb8a 100644 --- a/challenge-149/abigail/perl/ch-1.pl +++ b/challenge-149/abigail/perl/ch-1.pl @@ -29,7 +29,17 @@ use List::Util qw [sum]; # # Return the sum of the digits of its argument # -sub digitsum ($n) {sum $n =~ /\d/ag} +sub digitsum ($number) { + my $sum = 0; + my $base = 10; + while ($number > 0) { + use integer; + $sum += $number % $base; + $number /= $base; + } + return $sum; +} + # # Return whether the argument is a Fibonacci number. We do this by |
