Skip to content

Instantly share code, notes, and snippets.

@eric1234
Created September 19, 2009 10:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eric1234/189457 to your computer and use it in GitHub Desktop.
Save eric1234/189457 to your computer and use it in GitHub Desktop.
Solution to problem 1 on Project Euler
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