Wed Mar 28 15:59:31 CEST 2012
On 3/28/2012 8:16, Michael Poeltl wrote:
> yeah - of course 'while True' was the first, most obvious best way... ;-)
> but I was asked if there was a way without 'while True'
> and so I started the 'recursive function'
> and quick quick; RuntimeError-Exception -> not thinking much -> just adding
> two zeros to the default limit (quick and dirty) -> segfault ==> subject: python segfault ;-)
You give up too easily! Here's another way:
def get_steps2(pos=0, steps=0, level = 100):
if steps == 0:
pos = random.randint(-1,1)
if pos == 0:
steps += 2
pos += random.randint(-1,1)
if level == 0:
return (pos, steps)
res = get_steps2(pos,steps, level-1)
if not isinstance(res, tuple):
return get_steps2(res, res, level-1)
for i in range(200):
print ( get_steps2() )
Now the limit is 1267650600228229401496703205376. I hope that's enough.
More information about the Python-list