function Ack($m, $n) { if ($m == 0) { return $n + 1; } if ($n == 0) { return Ack($m - 1, 1); } return Ack($m - 1, Ack($m, $n - 1)); }
function Ack($m, $n) { $m = (int) $m; $n = (int) $n; if ($m == 0) { return $n + 1; } if ($n == 0) { return Ack($m - 1, 1); } return Ack($m - 1, Ack($m, $n - 1)); }
function ackermann() { $r = Ack(3, 7); print "Ack(3,7): {$r}\n"; $r = Ack(3, 6); print "Ack(3,6): {$r}\n"; $r = Ack(3, 6); print "Ack(3,6): {$r}\n"; $r = Ack(3, 5); print "Ack(3,5): {$r}\n"; $r = Ack(3, 5); print "Ack(3,5): {$r}\n"; $r = Ack(3, 5); print "Ack(3,5): {$r}\n"; }
function ackermann($n) { $r = Ack(3, $n); print "Ack(3,{$n}): {$r}\n"; }
<?php // The $TEMP = 1 from $n+1 should be DCEd. // { phc-option: -O3 --dump=codegen } // { phc-regex-output: !/= 1/ } function Ack($m, $n) { if ($m == 0) { return $n + 1; } } $r = Ack(3, 3); print "Ack(3,{$n}): {$r}\n";
static function ackermann() { Timing::Start("ackermann.php"); /*print "Ack(3,7): " .*/ Ack(3, 7); Timing::Stop(); }