aboutsummaryrefslogtreecommitdiff
path: root/challenge-033/rnuttall/perl6/ch-2.p6
blob: d76cf95b33be76ecf1426e342bbb26187c93116a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/usr/bin/env perl6
#    Task #2
#    Formatted Multiplication Table
#    Write a script to print 11x11 multiplication table, only the top half triangle.

sub MAIN($lim = 11) {
    # We can use a single format for all lines
    my         $fmt = "%3s%1s" ~ "%4s" x $lim ~ "\n";
    printf     $fmt,  'x', '|',        1..$lim;
    printf     $fmt, '---','+', '----' xx $lim;
    for 1..$lim -> $x {
        # use xx Sequence repetition to give spaces for lower half of table,
        # use Hyperop «*» to multiply out the visible values
        printf $fmt,  $x,  '|', ' ' xx $x-1, ($x..$lim) «*» $x;
    }
}