Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
18
Task/Anonymous-recursion/PHP/anonymous-recursion-3.php
Normal file
18
Task/Anonymous-recursion/PHP/anonymous-recursion-3.php
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
class fib_helper {
|
||||
function __invoke($n) {
|
||||
if ($n < 2)
|
||||
return 1;
|
||||
else
|
||||
return $this($n-1) + $this($n-2);
|
||||
}
|
||||
}
|
||||
|
||||
function fib($n) {
|
||||
if ($n < 0)
|
||||
throw new Exception('Negative numbers not allowed');
|
||||
$f = new fib_helper();
|
||||
return $f($n);
|
||||
}
|
||||
echo fib(8), "\n";
|
||||
?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue