Created
November 13, 2011 20:35
-
-
Save hyfather/1362640 to your computer and use it in GitHub Desktop.
My solution to problem #2 on projecteuler.net
This file contains hidden or 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 Array | |
def fibselect(&block) | |
o, i, array = 0, 1, [] | |
while i < length | |
o, i = i, i+o | |
array << self[i] | |
end | |
array.compact.select &block | |
end | |
end | |
p (0..4000000).to_a.fibselect{|x| x%2 == 0}.inject(:+) | |
#=> 4613732 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment