Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

15 lines (12 sloc) 0.509 kb
# Each new term in the Fibonacci sequence is generated by adding the p1 two terms. By starting with 1 and 2, the first 10 terms will be:
#
# 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
#
# By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
def fibonacci(p2, p1, sum)
next_number = p2 + p1
return sum if next_number >= 4000000
sum += next_number if next_number.even?
fibonacci p1, next_number, sum
end
p fibonacci(1, 2, 2)
Jump to Line
Something went wrong with that request. Please try again.