Skip to content

Instantly share code, notes, and snippets.

@releu
Created January 5, 2012 09:45
Show Gist options
  • Save releu/1564460 to your computer and use it in GitHub Desktop.
Save releu/1564460 to your computer and use it in GitHub Desktop.
Project Euler #2
class Array
def sum
inject(0) { |s, i| s + i }
end
end
array = [1, 2]
while array.last < 4000000
array << array[-2, 2].sum
end
puts array.select(&:even?).sum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment