Last active
January 24, 2017 04:31
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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