Skip to content

Instantly share code, notes, and snippets.

@gingeleski
Created January 6, 2015 06:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gingeleski/199a346ee193ed389772 to your computer and use it in GitHub Desktop.
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.
# 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