Skip to content

Instantly share code, notes, and snippets.

@abdollar
Created December 8, 2011 22:16
Show Gist options
  • Save abdollar/1448912 to your computer and use it in GitHub Desktop.
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.
sum [n | n <- [3..999], n `mod` 5 == 0 || n `mod` 3 == 0]
(3..999).find_all{|n| (n % 3 == 0) || (n % 5 == 0) }.inject{|sum,x| sum + x }
@abdollar
Copy link
Author

(3..999).select{|n| (n % 3 == 0) || (n % 5 == 0) }.inject(:+)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment