Created
January 6, 2015 06:30
-
-
Save gingeleski/199a346ee193ed389772 to your computer and use it in GitHub Desktop.
Finds the sum of all even-valued terms in the Fibonacci sequence that do not exceed 4 million.
This file contains 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
# Considering the terms in the Fibonacci sequence whose values | |
# do not exceed 4 million, find the sum of the even-valued terms. | |
x = 1 | |
y = 2 | |
sum = 2 | |
while x < 4000000 && y < 4000000 | |
x += y | |
sum += x if x % 2 == 0 | |
y += x | |
sum += y if y % 2 == 0 | |
end | |
sum |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment