Fibonacci sequence: Difference between revisions
Content deleted Content added
GordonBGood (talk | contribs) →{{header|Mathematica}} / {{header|Wolfram Language}}: simplification of more efficient recursive and iterative.... |
GordonBGood (talk | contribs) →Better Recursive doesn't need Memoization: shorten... |
||
Line 4,759: | Line 4,759: | ||
<lang python>def fibFastRec(n): |
<lang python>def fibFastRec(n): |
||
def fib(prvprv, prv, c): |
|||
⚫ | |||
else: |
|||
else: return fib(prv, prvprv + prv, c - 1) |
|||
return fib(0, 1, n)</lang> |
|||
⚫ | |||
return fib(0, 1, n - 2)</lang> |
|||
However, although much faster and not requiring memory, the above code can only process to a limited 'n' due to the limit on stack recursion depth by Python; it is better to use the iterative approach above or the generative one below. |
However, although much faster and not requiring memory, the above code can only process to a limited 'n' due to the limit on stack recursion depth by Python; it is better to use the iterative approach above or the generative one below. |