Advertisement
cwchen

[Perl 6] Recursion demo: fibonacci

Nov 15th, 2017
1,212
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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
RAW Paste Data Copied
Advertisement