daily pastebin goal
22%
SHARE
TWEET

[Perl 6] Recursion demo: fibonacci

cwchen Nov 15th, 2017 107 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";
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