Created
September 19, 2009 10:35
-
-
Save eric1234/189457 to your computer and use it in GitHub Desktop.
Solution to problem 1 on Project Euler
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
class Numeric | |
def divisible_by? num | |
self % num == 0 | |
end | |
end | |
module Enumerable | |
def sum &blk | |
blk = proc {|x| x} unless block_given? | |
inject(0) {|sum, element| sum + (blk[element] || 0)} | |
end | |
end | |
puts (1...1000).sum {|n| n if n.divisible_by? 3 or n.divisible_by? 5} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment