Last active
March 8, 2017 02:50
-
-
Save er2/5c153701ce6b22df73a10b654eaa393c to your computer and use it in GitHub Desktop.
Nth fibonacci number with perl 6, adapted from http://blogs.perl.org/users/ovid/2015/02/avoid-a-common-software-bug-by-using-perl-6.html
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
use experimental :cached; | |
sub MAIN(Int $nth) { | |
say fib($nth); | |
} | |
sub fib(Int $nth) is cached { | |
given $nth { | |
when 0 { 0 } | |
when 1 { 1 } | |
default { fib($nth-1) + fib($nth-2) } | |
} | |
} |
Author
er2
commented
Mar 8, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment