exercism-perl5

Repository for my Perl 5 Exercism exercises
git clone git://git.samirparikh.com/exercism-perl5
Log | Files | Refs

commit 5eec787cdd468d78827ef9725162f54a62f5e3d1
parent 933abf5ffebad44f22a47ae71bcf8a2c12364dbb
Author: Samir Parikh <noreply@samirparikh.com>
Date:   Thu, 25 Nov 2021 01:59:53 +0000

update SumOfMultiples.pm

Diffstat:
Msum-of-multiples/SumOfMultiples.pm | 18+++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/sum-of-multiples/SumOfMultiples.pm b/sum-of-multiples/SumOfMultiples.pm @@ -5,8 +5,24 @@ use Exporter qw<import>; our @EXPORT_OK = qw<sum_of_multiples>; sub sum_of_multiples { + # $input is a reference to a hash with two keys: factors and limit + # The value of factors is a reference to an array. Once we dereference + # that array, we can access the factors. + # The value of limit is the limit up to which we check the multiples. my ($input) = @_; - return undef; + my @factors = @{$input->{factors}}; + my $limit = $input->{limit}; + my $sum_of_multiples = 0; + #print "@factors\n"; + print join ":", @factors; + foreach my $factor (@factors) { + # if current factor is greater than or equal to the limit, + # skip to the next one + next if $factor >= $limit; + } + #print "$limit\n"; + #return undef; + return $sum_of_multiples; } 1;