Skip to content

Instantly share code, notes, and snippets.

@negamorgan
Created April 30, 2014 21:32
Show Gist options
  • Save negamorgan/23a05fa035e1b8a4acbe to your computer and use it in GitHub Desktop.
Save negamorgan/23a05fa035e1b8a4acbe to your computer and use it in GitHub Desktop.
euler-problem-2.rb
def even_fibonacci_numbers
fibonacci_numbers.select {|n| n.even? }.reduce(:+)
end
def fibonacci_numbers
numbers = [1, 2]
while numbers[-1] < 4_000_000 do
numbers << numbers[-2] + numbers[-1]
end
numbers[0..-2]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment