FANDOM


Problem 2 Edit

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:

1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...

Find the sum of all the even-valued terms in the sequence which do not exceed four million.

CodeEdit

new number n-1 1
new number n-2 1
new number cur
new number sum 0
new number t
hereis loop
set #cur #n-1 + #n-2
if #cur > 4000000 end
set #n-2 #n-1
set #n-1 #cur
set #t #cur % 2
if #t = 0 add
hereis e
goto loop
hereis add
set #sum #sum + #cur
goto e
hereis end
write #sum