Finding the sum of all the multiples of 3 or 5 below 1000

Finding the sum of all the multiples of 3 or 5 below 1000

This problem comes from Project Euler. Project Euler is a website with a bunch of computational problems designed to be solved with software applications.

find_sum_of_multiples.rb

=begin
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3,
5, 6 and 9. The sum of these multiples is 23.

Find the sum of all the multiples of 3 or 5 below 1000.
=end

class Euler
  def self.sum_of_multiples(number)
    range = (1...number).to_a
    sum = 0

    range.each do |n|
      if n % 3 == 0 || n % 5 == 0
        sum += n
      end
    end

    puts sum
  end
end

This can be executed from the command line by running:

ruby -r "./find_sum_of_multiples.rb" -e "Euler.sum_of_multiples 1000"