Sha256: 15552c23ad465691f9209b5a09820f105198e312a02f512ee70ab4441a70068e

Contents?: true

Size: 547 Bytes

Versions: 73

Compression:

Stored size: 547 Bytes

Contents

package SumOfMultiples;

use strict;
use warnings;
use List::Util 'sum';

sub new {
    my ($class, @multiples_of) = @_;

    bless { multiples_of => [@multiples_of] } => $class;
}

sub to {
    my ($self, $to) = @_;
    $to = $to - 1;
    my $sum;
    my @multiples;
    
    foreach my $num (1..$to) {
        foreach my $multiple_of ( @{ $self->{multiples_of} } ) {
            if ($num % $multiple_of == 0) {
                push @multiples => $num;
                last;
            }
        }
    }

    return (sum @multiples) || 0;
}

1;

Version data entries

73 entries across 73 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/perl5/exercises/sum-of-multiples/.meta/solutions/SumOfMultiples.pm
trackler-2.2.1.179 tracks/perl5/exercises/sum-of-multiples/.meta/solutions/SumOfMultiples.pm
trackler-2.2.1.178 tracks/perl5/exercises/sum-of-multiples/.meta/solutions/SumOfMultiples.pm
trackler-2.2.1.177 tracks/perl5/exercises/sum-of-multiples/.meta/solutions/SumOfMultiples.pm
trackler-2.2.1.176 tracks/perl5/exercises/sum-of-multiples/.meta/solutions/SumOfMultiples.pm
trackler-2.2.1.175 tracks/perl5/exercises/sum-of-multiples/.meta/solutions/SumOfMultiples.pm
trackler-2.2.1.174 tracks/perl5/exercises/sum-of-multiples/.meta/solutions/SumOfMultiples.pm
trackler-2.2.1.173 tracks/perl5/exercises/sum-of-multiples/.meta/solutions/SumOfMultiples.pm
trackler-2.2.1.172 tracks/perl5/exercises/sum-of-multiples/.meta/solutions/SumOfMultiples.pm
trackler-2.2.1.171 tracks/perl5/exercises/sum-of-multiples/.meta/solutions/SumOfMultiples.pm
trackler-2.2.1.170 tracks/perl5/exercises/sum-of-multiples/.meta/solutions/SumOfMultiples.pm
trackler-2.2.1.169 tracks/perl5/exercises/sum-of-multiples/.meta/solutions/SumOfMultiples.pm
trackler-2.2.1.167 tracks/perl5/exercises/sum-of-multiples/.meta/solutions/SumOfMultiples.pm
trackler-2.2.1.166 tracks/perl5/exercises/sum-of-multiples/.meta/solutions/SumOfMultiples.pm
trackler-2.2.1.165 tracks/perl5/exercises/sum-of-multiples/.meta/solutions/SumOfMultiples.pm
trackler-2.2.1.164 tracks/perl5/exercises/sum-of-multiples/.meta/solutions/SumOfMultiples.pm
trackler-2.2.1.163 tracks/perl5/exercises/sum-of-multiples/.meta/solutions/SumOfMultiples.pm
trackler-2.2.1.162 tracks/perl5/exercises/sum-of-multiples/.meta/solutions/SumOfMultiples.pm
trackler-2.2.1.161 tracks/perl5/exercises/sum-of-multiples/.meta/solutions/SumOfMultiples.pm
trackler-2.2.1.160 tracks/perl5/exercises/sum-of-multiples/.meta/solutions/SumOfMultiples.pm