You are viewing a single comment's thread. Return to all comments →
a very optimized solution with recursion
python def fib_sum_even(n, current, nextnum, sum_even): if current>n: return sum_even if current % 2 == 0: sum_even += current return fib_sum_even(n, nextnum, current+nextnum, sum_even)
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #2: Even Fibonacci numbers
You are viewing a single comment's thread. Return to all comments →
a very optimized solution with recursion
python def fib_sum_even(n, current, nextnum, sum_even): if current>n: return sum_even if current % 2 == 0: sum_even += current return fib_sum_even(n, nextnum, current+nextnum, sum_even)