Skip to content

Instantly share code, notes, and snippets.

@mathiasverraes
Created November 14, 2017 09:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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

0
1
1
2
3
5
8
13
21
34
55
89
144
233
377
610
987
1597
2584
4181
6765
10946
17711

Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 20480 bytes) in /in/pkNNB on line 4

Process exited with code 255.

Oh well, it was fun while it lasted.

@mathiasverraes
Copy link
Author

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