FrankKair / polyglot-euler

📜 Project Euler solutions in various programming languages
MIT License
73 stars 14 forks source link

Red 002 #97

Closed yvern closed 5 years ago

yvern commented 5 years ago

Hello! Thank you for your contribution to polyglot-euler.

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

Performance

Try it online!

Real time: 2.168 s
User time: 2.101 s
Sys. time: 0.041 s
CPU share: 98.83 %