daily pastebin goal
36%
SHARE
TWEET

[Perl 6] Fibonacci numbers in iterators.

cwchen Nov 28th, 2017 92 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. sub fib {
  2.     my $a = 0;
  3.     my $b = 1;
  4.    
  5.     gather {
  6.         loop {
  7.             take $a;
  8.             my $c = $a + $b;
  9.             $a = $b;
  10.             $b = $c;
  11.         }
  12.     }
  13. }
  14.  
  15. # (0 1 1 2 3 5 8 13 21 34 55)
  16. fib[10] == 55 or die "Wrong value";
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top