Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
20
Task/Y-combinator/PHP/y-combinator-4.php
Normal file
20
Task/Y-combinator/PHP/y-combinator-4.php
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
function pseudoY($f) {
|
||||
$g = function($w) use ($f) {
|
||||
return $f->bindTo(function() use ($w) {
|
||||
return call_user_func_array($w($w), func_get_args());
|
||||
});
|
||||
};
|
||||
return $g($g);
|
||||
}
|
||||
|
||||
$factorial = pseudoY(function($n) {
|
||||
return $n > 1 ? $n * $this($n - 1) : 1;
|
||||
});
|
||||
echo $factorial(10), "\n";
|
||||
|
||||
$fibonacci = pseudoY(function($n) {
|
||||
return $n > 1 ? $this($n - 1) + $this($n - 2) : $n;
|
||||
});
|
||||
echo $fibonacci(10), "\n";
|
||||
?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue