Created
April 30, 2014 21:32
-
-
Save negamorgan/23a05fa035e1b8a4acbe to your computer and use it in GitHub Desktop.
euler-problem-2.rb
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
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