Ackermann function
AUTHOR
Filip Sergot
The Ackermann function is a classic recursive example in computer science.
More
http://rosettacode.org/wiki/Ackermann_function#Raku
What's interesting here?
ternary chaining
recursive functions
Features used
ternary operator
- http://doc.perl6.org/language/operators#infix_%3F%3F_%21%21multi subs
- http://doc.perl6.org/syntax/multi
use v6;
sub A(Int $m, Int $n) {
$m == 0 ?? $n + 1 !!
$n == 0 ?? A($m - 1, 1 ) !!
A($m - 1, A($m, $n - 1));
}
A(1, 2).say;
# vim: expandtab shiftwidth=4 ft=perl6