Hello! Thank you for your contribution to polyglot-euler.
[✅] I checked CONTRIBUTING.md for my programming language of choice.
How the solution works
start initialising sum accumulator, starting fib state [1 1] and step, the iteration variable and next fib number.
fibstep function takes a fib state and gives the next fib number.
a while loop, that keeps track of step variable, so it doest not exceed 4000000, and on each iteration it updates step to be the result of fibstep, and if it is even, is added to sum, and then we pop out the first element in fib and push the new one, step
Hello! Thank you for your contribution to
polyglot-euler
.How the solution works
start initialising
sum
accumulator, startingfib
state[1 1]
andstep
, the iteration variable and next fib number.fibstep
function takes afib
state and gives the next fib number.a
while
loop, that keeps track ofstep
variable, so it doest not exceed 4000000, and on each iteration it updatesstep
to be the result offibstep
, and if it is even, is added tosum
, and then we pop out the first element infib
and push the new one,step
Performance
Try it online!