Created
October 16, 2014 03:18
-
-
Save marcoonroad/7b8710112d4da3301e85 to your computer and use it in GitHub Desktop.
Fibonacci using multi-dispatch functions at Perl 6...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl6 | |
use v6; | |
multi fib(Int $n where -> $n { $n ~~ any(1, 2) }) { 1 } | |
multi fib(Int $n where -> $n { $n > 2 }) { fib($n - 1) + fib($n - 2) } | |
say fib 10; # 55 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment