aboutsummaryrefslogtreecommitdiff
path: root/challenge-017/arne-sommer/perl6/ackermann2
blob: 98286c26f986b81c4d9a32133eb11b46c2a65c86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#! /usr/bin/env perl6

subset PositiveInt of Int where * > 0;
subset PositiveIntZero of Int where * >= 0;

sub MAIN(PositiveIntZero \m, PositiveIntZero \n)
{
  say A(m, n);
}

multi A(0, PositiveIntZero \n)
{
  return n + 1;
}

multi A(PositiveInt \m, 0)
{
  return A(m - 1, 1);
}

multi A(PositiveInt \m, PositiveInt \n)
{
  return  A(m - 1, A(m, n - 1));
}