I like competitive programming (like Meta Hacker Cup). Where you solve algorithmic puzzles in limited time. In many problems, a recursive solution feels more natural than an iterative one — but Python’s recursion depth limit (usually around 1000) makes it impractical for larger inputs.

So I built a small macro — @call_once — that lets you write recursive functions with virtually unlimited recursion depth.

Example

Let’s take a simple Fibonacci example:

def fib(n):
if n <= 1:
return n
return fib(n - 1) + fib(n - 2)

print(fib(200_000) % 1_000)

This will crash immediately — Python’s call stack can’t handle that depth.

But with one decorator:

@call_once
def fib(n):
if n <= 1:
return n
return fib(n - 1) + fib(n -...

Similar Posts

Loading similar posts...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help