Skip to content

Instantly share code, notes, and snippets.

@mjhea0
Created April 23, 2013 16:33
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 mjhea0/5445198 to your computer and use it in GitHub Desktop.
Save mjhea0/5445198 to your computer and use it in GitHub Desktop.
Find the sum of the odd-valued terms of the Fibonacci sequence whose values do not exceed 2,000.
num1 = 0
num2 = 1
i = 0
total = 0
while i <= 2000
# add previous two values
i = num1 + num2
# if i is odd, add it to the total
if i % 2 != 0
total = total + i
end
num1 = num2
num2 = i
end
puts total
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment