1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/tests/shootout/LICENCE.txt Sat Dec 02 00:23:46 2006 +0100
1.3 @@ -0,0 +1,27 @@
1.4 +Copyright © 2004,2005,2006 Brent Fulgham
1.5 +
1.6 +All rights reserved.
1.7 +
1.8 +Redistribution and use in source and binary forms, with or without
1.9 +modification, are permitted provided that the following conditions are met:
1.10 +
1.11 + * Redistributions of source code must retain the above copyright notice, this
1.12 + list of conditions and the following disclaimer.
1.13 + * Redistributions in binary form must reproduce the above copyright notice,
1.14 + this list of conditions and the following disclaimer in the documentation
1.15 + and/or other materials provided with the distribution.
1.16 + * Neither the name of "The Computer Language Shootout Benchmarks" nor the
1.17 + name of "Computer Language Shootout" nor the names of its contributors may
1.18 + be used to endorse or promote products derived from this software without
1.19 + specific prior written permission.
1.20 +
1.21 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1.22 +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1.23 +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1.24 +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
1.25 +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1.26 +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
1.27 +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
1.28 +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
1.29 +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1.30 +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/tests/shootout/binary-trees.py Sat Dec 02 00:23:46 2006 +0100
2.3 @@ -0,0 +1,44 @@
2.4 +# The Computer Language Shootout Benchmarks
2.5 +# http://shootout.alioth.debian.org/
2.6 +#
2.7 +# contributed by Antoine Pitrou
2.8 +# modified by Dominique Wahli
2.9 +
2.10 +from sys import argv
2.11 +
2.12 +def make_tree(item, depth):
2.13 + if depth > 0:
2.14 + item2 = 2 * item
2.15 + depth -= 1
2.16 + return (item, make_tree(item2 - 1, depth), make_tree(item2, depth))
2.17 + else:
2.18 + return (item, None, None)
2.19 +
2.20 +def check_tree((item, left, right)):
2.21 + if left is not None:
2.22 + return item + check_tree(left) - check_tree(right)
2.23 + else:
2.24 + return item
2.25 +
2.26 +def main():
2.27 + min_depth = 4
2.28 + max_depth = max(min_depth + 2, int(argv[1]))
2.29 + stretch_depth = max_depth + 1
2.30 +
2.31 + print "stretch tree of depth %d\t check: %d" % (stretch_depth, check_tree(make_tree(0, stretch_depth)))
2.32 +
2.33 + long_lived_tree = make_tree(0, max_depth)
2.34 +
2.35 + for depth in xrange(min_depth, stretch_depth, 2):
2.36 + iterations = 2**(max_depth - depth + min_depth)
2.37 +
2.38 + check = 0
2.39 + for i in xrange(1, iterations + 1):
2.40 + check += check_tree(make_tree(i, depth)) + check_tree(make_tree(-i, depth))
2.41 +
2.42 + print "%d\t trees of depth %d\t check: %d" % (iterations * 2, depth, check)
2.43 +
2.44 + print "long lived tree of depth %d\t check: %d" % (max_depth, check_tree(long_lived_tree))
2.45 +
2.46 +if __name__ == '__main__':
2.47 + main()