Created
December 8, 2011 22:16
-
-
Save abdollar/1448912 to your computer and use it in GitHub Desktop.
Add all the natural numbers below one thousand that are multiples of 3 or 5.
This file contains 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
sum [n | n <- [3..999], n `mod` 5 == 0 || n `mod` 3 == 0] |
This file contains 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
(3..999).find_all{|n| (n % 3 == 0) || (n % 5 == 0) }.inject{|sum,x| sum + x } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
(3..999).select{|n| (n % 3 == 0) || (n % 5 == 0) }.inject(:+)