# $Id$

use strict;
use lib '../../lib';

use Parrot::Test tests => 1;

sub test {
    language_output_is('python', $_[0], '', $_[1]);
}

test(<<'CODE', 'b1.py');
def depth0(n):
    try:
        n = depth0(n+1)
    except RuntimeError:
        pass
    return n

def depth1(n, pea):
    p = (pea, pea)
    for i in xrange(n):
        p = (p, pea)
    try:
        n, p = depth1(n+1, p)
    except RuntimeError:
        pass
    return n, p

def main():
    print depth0(0) >= 996
    pea = []
    base, p = depth1(0, pea)
    print base >= 996
    pea.append(p)
    while p[1] is not pea:
        q = p[1]
        n = 0
        while p[1] is q:
            n += 1
            p = p[0]
        if n != base+1:
            raise RuntimeError, (n, base)
        base -= 1
    print base
    del pea[:]

if __name__ == '__main__':
    main()
CODE

# $Id$

use strict;
use lib '../../lib';

use Parrot::Test tests => 1;

sub test {
    language_output_is('python', $_[0], '', $_[1]);
}

test(<<'CODE', 'b1.py');
def depth0(n):
    try:
        n = depth0(n+1)
    except RuntimeError:
        pass
    return n

def depth1(n, pea):
    p = (pea, pea)
    for i in xrange(n):
        p = (p, pea)
    if n >= 99: return n, p
    try:
        n, p = depth1(n+1, p)
    except RuntimeError:
        pass
    return n, p

def main():
    print depth0(0) >= 996
    pea = []
    base, p = depth1(0, pea)
    print base >= 996
    pea.append(p)
    while p[1] is not pea:
        q = p[1]
        n = 0
        while p[1] is q:
            n += 1
            p = p[0]
        if n != base+1:
            raise RuntimeError, (n, base)
        base -= 1
    print base
    del pea[:]

if __name__ == '__main__':
    main()
CODE

Reduce the number of iterations
Reduce the number of iterations


git-svn-id: 6e74a02f85675cec270f5d931b0f6998666294a3@7414 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
