aboutsummaryrefslogtreecommitdiff
path: root/challenge-017/feng-chang/perl6/ch-1.p6
blob: 9081f569106c58aa286a0c98a9c439bc39a0a1d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/env perl6

my @pool;

say "A(0,$_) ", A(0, $_) for 0..9;
say "A(1,$_) ", A(1, $_) for 0..9;
say "A(2,$_) ", A(2, $_) for 0..9;
say "A(3,$_) ", A(3, $_) for 0..9;

sub A(UInt $m, UInt $n) returns UInt {
    return @pool[$m][$n] if @pool[$m][$n].defined;

    if $m == 0 {
        @pool[0][$n] = $n + 1;
    } elsif $n == 0 {
        @pool[$m][0] = A($m - 1, 1);
    } else {
        @pool[$m][$n] = A($m - 1, A($m, $n - 1));
    }

    return @pool[$m][$n];
}