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.119 tracks/perl5/exercises/sum-of-multiples/.meta/solutions/SumOfMultiples.pm
trackler-2.2.1.118 tracks/perl5/exercises/sum-of-multiples/.meta/solutions/SumOfMultiples.pm
trackler-2.2.1.117 tracks/perl5/exercises/sum-of-multiples/.meta/solutions/SumOfMultiples.pm
trackler-2.2.1.116 tracks/perl5/exercises/sum-of-multiples/.meta/solutions/SumOfMultiples.pm
trackler-2.2.1.115 tracks/perl5/exercises/sum-of-multiples/.meta/solutions/SumOfMultiples.pm
trackler-2.2.1.114 tracks/perl5/exercises/sum-of-multiples/.meta/solutions/SumOfMultiples.pm
trackler-2.2.1.113 tracks/perl5/exercises/sum-of-multiples/.meta/solutions/SumOfMultiples.pm
trackler-2.2.1.111 tracks/perl5/exercises/sum-of-multiples/.meta/solutions/SumOfMultiples.pm
trackler-2.2.1.110 tracks/perl5/exercises/sum-of-multiples/.meta/solutions/SumOfMultiples.pm
trackler-2.2.1.109 tracks/perl5/exercises/sum-of-multiples/.meta/solutions/SumOfMultiples.pm
trackler-2.2.1.108 tracks/perl5/exercises/sum-of-multiples/.meta/solutions/SumOfMultiples.pm
trackler-2.2.1.107 tracks/perl5/exercises/sum-of-multiples/.meta/solutions/SumOfMultiples.pm
trackler-2.2.1.106 tracks/perl5/exercises/sum-of-multiples/.meta/solutions/SumOfMultiples.pm