Skip to content

Instantly share code, notes, and snippets.

@mathiasverraes
Created November 14, 2017 09:46
Show Gist options
  • Save mathiasverraes/785597196f55d9355ed25684dee76b74 to your computer and use it in GitHub Desktop.
Save mathiasverraes/785597196f55d9355ed25684dee76b74 to your computer and use it in GitHub Desktop.
Supposedly Lazy Fibonacci
<?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();
}
}
@mathiasverraes
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment