I wrote this piece of code to compute the number of combinations:
def fact(n):
return 1 if(n == 1) else n * fact(n - 1)
def combinations(n,k):
retur
Your Recursion depth out of the limit.
Recursion is not the most idiomatic way to do things in Python, as it doesn't have tail recursion optimization thus making impractical the use of recursion as a substitute for iteration (even if in your example the function is not tail-recursive, that wouldn't help anyway). Basically, that means that you shouldn't use it for things that have a complexity greater than linear if you expect your inputs to be large.
If you have a platform that supports a higher limit, you can set the limit higher:
sys.setrecursionlimit(some_number)
sys.setrecursionlimit(some_number)
This function set the maximum depth of the Python interpreter stack to limit. This limit prevents infinite recursion from causing an overflow of the C stack and crashing Python. The highest possible limit is platform-dependent. A user may need to set the limit higher when she has a program that requires deep recursion and a platform that supports a higher limit. This should be done with care because a too-high limit can lead to a crash.
ref:
Python recursive function error: “maximum recursion depth exceeded”
Python max recursion , question about sys.setrecursionlimit()