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