Last active
December 15, 2015 18:59
-
-
Save aarti/5307924 to your computer and use it in GitHub Desktop.
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
total= (1..999).reduce(0) do |sum,n| | |
n%3 == 0 || n%5 == 0 ? sum + n : sum | |
end | |
puts total |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment