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.139 tracks/perl5/exercises/sum-of-multiples/.meta/solutions/SumOfMultiples.pm
trackler-2.2.1.138 tracks/perl5/exercises/sum-of-multiples/.meta/solutions/SumOfMultiples.pm
trackler-2.2.1.137 tracks/perl5/exercises/sum-of-multiples/.meta/solutions/SumOfMultiples.pm
trackler-2.2.1.136 tracks/perl5/exercises/sum-of-multiples/.meta/solutions/SumOfMultiples.pm
trackler-2.2.1.135 tracks/perl5/exercises/sum-of-multiples/.meta/solutions/SumOfMultiples.pm
trackler-2.2.1.134 tracks/perl5/exercises/sum-of-multiples/.meta/solutions/SumOfMultiples.pm
trackler-2.2.1.133 tracks/perl5/exercises/sum-of-multiples/.meta/solutions/SumOfMultiples.pm
trackler-2.2.1.132 tracks/perl5/exercises/sum-of-multiples/.meta/solutions/SumOfMultiples.pm
trackler-2.2.1.131 tracks/perl5/exercises/sum-of-multiples/.meta/solutions/SumOfMultiples.pm
trackler-2.2.1.130 tracks/perl5/exercises/sum-of-multiples/.meta/solutions/SumOfMultiples.pm
trackler-2.2.1.129 tracks/perl5/exercises/sum-of-multiples/.meta/solutions/SumOfMultiples.pm
trackler-2.2.1.128 tracks/perl5/exercises/sum-of-multiples/.meta/solutions/SumOfMultiples.pm
trackler-2.2.1.127 tracks/perl5/exercises/sum-of-multiples/.meta/solutions/SumOfMultiples.pm
trackler-2.2.1.126 tracks/perl5/exercises/sum-of-multiples/.meta/solutions/SumOfMultiples.pm
trackler-2.2.1.125 tracks/perl5/exercises/sum-of-multiples/.meta/solutions/SumOfMultiples.pm
trackler-2.2.1.124 tracks/perl5/exercises/sum-of-multiples/.meta/solutions/SumOfMultiples.pm
trackler-2.2.1.123 tracks/perl5/exercises/sum-of-multiples/.meta/solutions/SumOfMultiples.pm
trackler-2.2.1.122 tracks/perl5/exercises/sum-of-multiples/.meta/solutions/SumOfMultiples.pm
trackler-2.2.1.121 tracks/perl5/exercises/sum-of-multiples/.meta/solutions/SumOfMultiples.pm
trackler-2.2.1.120 tracks/perl5/exercises/sum-of-multiples/.meta/solutions/SumOfMultiples.pm