- var_dump: documentation ( source)
- pow: documentation ( source)
<?php
for ($i = 0; $i < 16; $i++) {
var_dump(method($i) . "\t" . method1($i) . "\t" . pow(2, $i-1));
}
function method($n) {
if ($n <= 0) return 0;
if ($n == 1) return 1;
if ($n == 2) return 2;
if ($n == 3) return 4;
return method($n - 1) + method($n - 2) + method($n - 3);
}
function method1($n) {
if ($n <= 0) return 0;
$r = 1;
for ($i = 0; $i < $n; $i++) {
$r += method1($i);
}
return $r;
}