Skip to content

Instantly share code, notes, and snippets.

@romerobrjp
Last active January 24, 2017 04:31
Show Gist options
  • Save romerobrjp/a5bbb72b0b303dbe4ebb702f6d6381d3 to your computer and use it in GitHub Desktop.
Save romerobrjp/a5bbb72b0b303dbe4ebb702f6d6381d3 to your computer and use it in GitHub Desktop.
# 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.
class Challenges
# www.projecteuler.net
# 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.
def multiples_of_3_and_5
(1...1000).select { |n| n if (n % 3 == 0) || (n % 5 == 0) }.inject(:+)
end
end
puts "challenge 1: #{Challenges.new.multiples_of_3_and_5}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment