Skip to content

Instantly share code, notes, and snippets.

@er2
Last active March 8, 2017 02:50
Show Gist options
  • Save er2/5c153701ce6b22df73a10b654eaa393c to your computer and use it in GitHub Desktop.
Save er2/5c153701ce6b22df73a10b654eaa393c to your computer and use it in GitHub Desktop.
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) }
}
}
@er2
Copy link
Author

er2 commented Mar 8, 2017

eric@eric-x240:hacks§ time perl6 nthfib.p6 1000
43466557686937456435688527675040625802564660517371780402481729089536555417949051890403879840079255169295922593080322634775209689623239873322471161642996440906533187938298969649928516003704476137795166849228875

real	0m0.627s
user	0m0.596s
sys	0m0.028s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment