Created
September 19, 2009 11:16
-
-
Save eric1234/189461 to your computer and use it in GitHub Desktop.
Problem 2 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 even? | |
self % 2 == 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 | |
def fib(limit, *args) | |
return [args.last] if args.sum > limit | |
fib(limit, args.last, args.sum) << args.first | |
end | |
puts fib(4000000, 1).sum {|n| n if n.even?} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment