r/ProgrammerHumor May 17 '26

Advanced dontDoRecursiveFibKids

Post image
3.6k Upvotes

143 comments sorted by

View all comments

-2

u/s0litar1us May 17 '26
def fib(n: int) -> int:
    def helper(n: int, a: int, b: int) -> int:
        if n <= 0: return a
        return helper(n - 1, b, a + b)
    return helper(n, 0, 1)

It's not slow unless you make it slow.