Join Nostr
2026-05-10 17:46:02 UTC
in reply to

Trey Hunner 🐍 on Nostr: The number of function calls needed to compute the recursive version of ...

The number of function calls needed to compute the recursive version of "fibonacci(n)" is actually GREATER than the return value itself! https://pym.dev/p/232bf/

Of course, throwing a functools.cache decorator on fibonacci would fix this problem entirely.

So if you really prefer the recursive version, you CAN use it. But personally, I don't find it easier to reason about than the non-recursive version.

So when IS recursion the right tool...?

🧵 (5/6)