Created
November 14, 2017 09:46
-
-
Save mathiasverraes/785597196f55d9355ed25684dee76b74 to your computer and use it in GitHub Desktop.
Supposedly Lazy Fibonacci
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
foreach (fib() as $x) echo "$x\n"; | |
function fib () { | |
yield 0; yield 1; | |
$f = fib(); $g = fib(); | |
$g->next(); | |
while (true) { | |
yield $f->current() + $g->current(); | |
$f->next(); $g->next(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Oh well, it was fun while it lasted.