# HG changeset patch # User paulb@localhost.localdomain # Date 1165070433 -3600 # Node ID b2acc897e5e95e70f5d898e8befe8b57636c4620 # Parent 26af16cddaa26054aa5ae39ea7277ed9f71ae1db Simplified the binary tree example to work without the sys module and print statements. diff -r 26af16cddaa2 -r b2acc897e5e9 tests/shootout/binary-trees.py --- a/tests/shootout/binary-trees.py Sat Dec 02 02:20:47 2006 +0100 +++ b/tests/shootout/binary-trees.py Sat Dec 02 15:40:33 2006 +0100 @@ -4,7 +4,7 @@ # contributed by Antoine Pitrou # modified by Dominique Wahli -from sys import argv +#from sys import argv def make_tree(item, depth): if depth > 0: @@ -14,7 +14,8 @@ else: return (item, None, None) -def check_tree((item, left, right)): +def check_tree(tree): + (item, left, right) = tree if left is not None: return item + check_tree(left) - check_tree(right) else: @@ -22,10 +23,10 @@ def main(): min_depth = 4 - max_depth = max(min_depth + 2, int(argv[1])) + max_depth = max(min_depth + 2, 16) #int(argv[1])) stretch_depth = max_depth + 1 - print "stretch tree of depth %d\t check: %d" % (stretch_depth, check_tree(make_tree(0, stretch_depth))) + #print "stretch tree of depth %d\t check: %d" % (stretch_depth, check_tree(make_tree(0, stretch_depth))) long_lived_tree = make_tree(0, max_depth) @@ -36,9 +37,9 @@ for i in xrange(1, iterations + 1): check += check_tree(make_tree(i, depth)) + check_tree(make_tree(-i, depth)) - print "%d\t trees of depth %d\t check: %d" % (iterations * 2, depth, check) + #print "%d\t trees of depth %d\t check: %d" % (iterations * 2, depth, check) - print "long lived tree of depth %d\t check: %d" % (max_depth, check_tree(long_lived_tree)) + #print "long lived tree of depth %d\t check: %d" % (max_depth, check_tree(long_lived_tree)) if __name__ == '__main__': main()