1 # The Computer Language Shootout Benchmarks
2 # http://shootout.alioth.debian.org
4 # contributed by Jesse Millikan
10 tree
[1] + item_check(tree
[0]) - item_check(tree
[2])
14 def bottom_up_tree(item
, depth
)
18 [bottom_up_tree(item_item
- 1, depth
), item
, bottom_up_tree(item_item
, depth
)]
24 max_depth
= ARGV[0].to_i
27 max_depth
= min_depth
+ 2 if min_depth
+ 2 > max_depth
29 stretch_depth
= max_depth
+ 1
30 stretch_tree
= bottom_up_tree(0, stretch_depth
)
32 puts
"stretch tree of depth #{stretch_depth}\t check: #{item_check(stretch_tree)}"
35 long_lived_tree
= bottom_up_tree(0, max_depth
)
37 min_depth
.step(max_depth
+ 1, 2) do |depth
|
38 iterations
= 2**(max_depth
- depth
+ min_depth
)
42 for i
in 1..iterations
43 temp_tree
= bottom_up_tree(i
, depth
)
44 check
+= item_check(temp_tree
)
46 temp_tree
= bottom_up_tree(-i
, depth
)
47 check
+= item_check(temp_tree
)
50 puts
"#{iterations * 2}\t trees of depth #{depth}\t check: #{check}"
53 puts
"long lived tree of depth #{max_depth}\t check: #{item_check(long_lived_tree)}"