Sha256: 94570964007225ba4d73286b8c9726b48f5a74862d98eb2489ae29727e9efd53

Contents?: true

Size: 540 Bytes

Versions: 323

Compression:

Stored size: 540 Bytes

Contents

package Example;

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

323 entries across 323 versions & 1 rubygems

Version Path
trackler-2.2.1.65 tracks/perl5/exercises/sum-of-multiples/Example.pm
trackler-2.2.1.64 tracks/perl5/exercises/sum-of-multiples/Example.pm
trackler-2.2.1.63 tracks/perl5/exercises/sum-of-multiples/Example.pm
trackler-2.2.1.62 tracks/perl5/exercises/sum-of-multiples/Example.pm
trackler-2.2.1.61 tracks/perl5/exercises/sum-of-multiples/Example.pm
trackler-2.2.1.60 tracks/perl5/exercises/sum-of-multiples/Example.pm
trackler-2.2.1.59 tracks/perl5/exercises/sum-of-multiples/Example.pm
trackler-2.2.1.58 tracks/perl5/exercises/sum-of-multiples/Example.pm
trackler-2.2.1.57 tracks/perl5/exercises/sum-of-multiples/Example.pm
trackler-2.2.1.56 tracks/perl5/exercises/sum-of-multiples/Example.pm
trackler-2.2.1.55 tracks/perl5/exercises/sum-of-multiples/Example.pm
trackler-2.2.1.54 tracks/perl5/exercises/sum-of-multiples/Example.pm
trackler-2.2.1.53 tracks/perl5/exercises/sum-of-multiples/Example.pm
trackler-2.2.1.52 tracks/perl5/exercises/sum-of-multiples/Example.pm
trackler-2.2.1.51 tracks/perl5/exercises/sum-of-multiples/Example.pm
trackler-2.2.1.50 tracks/perl5/exercises/sum-of-multiples/Example.pm
trackler-2.2.1.49 tracks/perl5/exercises/sum-of-multiples/Example.pm
trackler-2.2.1.48 tracks/perl5/exercises/sum-of-multiples/Example.pm
trackler-2.2.1.47 tracks/perl5/exercises/sum-of-multiples/Example.pm
trackler-2.2.1.46 tracks/perl5/exercises/sum-of-multiples/Example.pm