@ 2014-09-09T07:27:43Z <?php
class Tree {
public $i;
public $l;
public $r;
public function __construct($item, $depth) {
$this->i = $item;
if($depth) {
$this->l = new Tree($item * 2 - 1, --$depth);
$this->r = new Tree($item * 2, $depth);
}
}
public function check() {
return $this->i
+ ($this->l->l === null ? $this->l->check() : $this->l->i)
- ($this->r->l === null ? $this->r->check() : $this->r->i);
}
}
$minDepth = 10;
$n = $argc == 2 ? $argv[1] : 1;
$maxDepth = $minDepth + 2 > $n ? $minDepth + 2 : $n;
$stretchDepth = $maxDepth + 1;
$stretch = new Tree(0, $stretchDepth);
printf("stretch tree of depth %d\t check: %d\n",
$stretchDepth, $stretch->check());
unset($stretch);
$longLivedTree = new Tree(0, $maxDepth);
$iterations = 1 << $maxDepth;
do
{
$check = 0;
for($i = 1; $i <= $iterations; ++$i)
{
$check += (new Tree($i, $minDepth))->check()
+ (new Tree(-$i, $minDepth))->check();
}
printf("%d\t trees of depth %d\t check: %d\n",
$iterations<<1, $minDepth, $check);
$minDepth += 2;
$iterations >>= 2;
}
while($minDepth <= $maxDepth);
printf("long lived tree of depth %d\t check: %d\n",
$maxDepth, $longLivedTree->check());
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 7.0.0 - 7.0.20 , 7.1.0 - 7.1.20 , 7.2.0 - 7.2.11 , 7.2.30 , 7.3.16 - 7.3.17 , 7.3.19 , 7.3.21 - 7.3.23 , 7.3.30 - 7.3.33 , 7.4.0 - 7.4.3 , 7.4.6 - 7.4.7 , 7.4.9 - 7.4.11 , 7.4.20 , 7.4.23 - 7.4.33 , 8.0.1 , 8.0.5 - 8.0.7 , 8.0.9 - 8.0.30 , 8.1.0 - 8.1.24 , 8.1.28 , 8.2.0 - 8.2.11 , 8.2.16 - 8.2.18 , 8.3.3 - 8.3.6 stretch tree of depth 13 check: -1
8192 trees of depth 10 check: -8192
Process exited with code 137 . Output for 7.4.5 , 8.1.25 - 8.1.27 , 8.2.12 - 8.2.15 , 8.3.0 - 8.3.2 stretch tree of depth 13 check: -1
8192 trees of depth 10 check: -8192
2048 trees of depth 12 check: -2048
long lived tree of depth 12 check: -1
Output for 5.4.0 - 5.4.45 , 5.5.24 - 5.5.35 , 5.6.8 - 5.6.21 , 7.2.29 , 7.2.31 - 7.2.33 , 7.3.18 , 7.3.20 , 7.3.24 - 7.3.29 , 7.4.4 , 7.4.8 , 7.4.12 - 7.4.16 , 7.4.21 - 7.4.22 , 8.0.0 , 8.0.2 - 8.0.3 , 8.0.8 stretch tree of depth 13 check: -1
Process exited with code 137 . Output for 5.1.0 - 5.1.6 , 5.2.0 - 5.2.17 , 5.3.0 - 5.3.29 Parse error: syntax error, unexpected T_OBJECT_OPERATOR in /in/ddVAG on line 42
Process exited with code 255 . Output for 5.0.0 - 5.0.5 Parse error: parse error, unexpected T_OBJECT_OPERATOR in /in/ddVAG on line 42
Process exited with code 255 . Output for 4.4.2 - 4.4.9 Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/ddVAG on line 4
Process exited with code 255 . Output for 4.3.0 - 4.3.1 , 4.3.5 - 4.3.11 , 4.4.0 - 4.4.1 Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/ddVAG on line 4
Process exited with code 255 . Output for 4.3.2 - 4.3.4 Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/ddVAG on line 4
Process exited with code 255 . preferences:dark mode live preview
227.62 ms | 401 KiB | 312 Q