Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

commented Nov 14, 2017

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

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.