Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sub fib(Int $n where $n >= 0) {
- state %cache = 0 => 0, 1 => 1;
- if %cache{$n}:exists {
- return %cache{$n};
- }
- my $out = fib($n - 1) + fib($n - 2);
- %cache{$n} = $out;
- $out;
- }
- fib(10) == 55 or die "Wrong number";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement