Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -2,12 +2,15 @@
|
|||
function fib($n) {
|
||||
if ($n < 0)
|
||||
throw new Exception('Negative numbers not allowed');
|
||||
else if ($n < 2)
|
||||
return 1;
|
||||
else {
|
||||
$f = __FUNCTION__;
|
||||
return $f($n-1) + $f($n-2);
|
||||
}
|
||||
$f = function($n) { // This function must be called using call_user_func() only
|
||||
if ($n < 2)
|
||||
return 1;
|
||||
else {
|
||||
$g = debug_backtrace()[1]['args'][0];
|
||||
return call_user_func($g, $n-1) + call_user_func($g, $n-2);
|
||||
}
|
||||
};
|
||||
return call_user_func($f, $n);
|
||||
}
|
||||
echo fib(8), "\n";
|
||||
?>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue