Sha256: 619391d237337ee954a900edbb62e2cfcce07e31538dd1120421d521817fdf5a

Contents?: true

Size: 362 Bytes

Versions: 129

Compression:

Stored size: 362 Bytes

Contents

module BookKeeping
  VERSION = 2
end

class SumOfMultiples
  attr_reader :multiples
  def initialize(*multiples)
    @multiples = multiples
  end

  def to(limit)
    sum = 0
    (1...limit).each do |i|
      sum += i if multiple?(i)
    end
    sum
  end

  private

  def multiple?(i)
    multiples.any? do |multiple|
      i % multiple == 0
    end
  end
end

Version data entries

129 entries across 129 versions & 1 rubygems

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