Any Python Gurus?


log in or register to remove this ad


alright, i've given into peer pressure and taken a look at your beloved Python. :)

Now, can anyone tell me a way of getting around its max recursion depth?
 

ender_wiggin said:
alright, i've given into peer pressure and taken a look at your beloved Python. :)

Now, can anyone tell me a way of getting around its max recursion depth?

Try to avoid heavy recursion. If you want to experiment you can

Code:
import sys
sys.setrecursionlimit(1000)

# code here

setrecursionlimit( limit)
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.
 


As far as I know there's only one 3x3 magic square (you can also rotate it etc). There are however 9! permutations of [1,2,3,4,5,6,7,8,9] if you want to try all the possible combinations and brute-force the solutions.
 




If you have a function return a number, let's say 0, does that come out as an integer?

Can I do this as a recursive call?

g = g + strategy(n+1,b,m,p,g)

It says I'm trying to add integer and "nontype"
 

Remove ads

Top