Skip to content

Instantly share code, notes, and snippets.

@hyfather
Created November 13, 2011 20:35
Show Gist options
  • Save hyfather/1362640 to your computer and use it in GitHub Desktop.
Save hyfather/1362640 to your computer and use it in GitHub Desktop.
My solution to problem #2 on projecteuler.net
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