1 # The Computer Language Shootout Benchmarks
2 # http://shootout.alioth.debian.org
4 # contributed by Jesse Millikan
7 def STDOUT.write_ *args
14 tree[1] + item_check(tree[0]) - item_check(tree[2])
18 def bottom_up_tree(item, depth)
22 [bottom_up_tree(item_item - 1, depth), item, bottom_up_tree(item_item, depth)]
28 max_depth = 12 # 16 # ARGV[0].to_i
31 max_depth = min_depth + 2 if min_depth + 2 > max_depth
33 stretch_depth = max_depth + 1
34 stretch_tree = bottom_up_tree(0, stretch_depth)
36 puts "stretch tree of depth #{stretch_depth}\t check: #{item_check(stretch_tree)}"
39 long_lived_tree = bottom_up_tree(0, max_depth)
41 min_depth.step(max_depth + 1, 2) do |depth|
42 iterations = 2**(max_depth - depth + min_depth)
46 for i in 1..iterations
47 temp_tree = bottom_up_tree(i, depth)
48 check += item_check(temp_tree)
50 temp_tree = bottom_up_tree(-i, depth)
51 check += item_check(temp_tree)
54 puts "#{iterations * 2}\t trees of depth #{depth}\t check: #{check}"
57 puts "long lived tree of depth #{max_depth}\t check: #{item_check(long_lived_tree)}"