Advertisement
cwchen

[Perl 6] Recursion demo: fibonacci

Nov 15th, 2017
3,285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 6 0.21 KB | None | 0 0
  1. sub fib(Int $n where $n >= 0) returns Int {
  2.     if $n == 0 {
  3.         return 0;
  4.     } elsif $n == 1 {
  5.         return 1;
  6.     }
  7.    
  8.     fib($n - 1) + fib($n - 2);
  9. }
  10.  
  11. fib(10) == 55 or die "Wrong number";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement