blob: f9cd99bbd5eccbced9c104b55d61f96f6bba6bc4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
#!/usr/bin/env perl6
# challenge-033/ch-2.p6 - Print multiplication table
#
# Ryan Thompson <rjt@cpan.org>
use v6;
sub MAIN(Int $max = 11) {
my $w = ($max*$max).chars; # Maximum width in table
my $fmt = "%{$w}s"; # Evenly sized columns
my @n = 1..$max; # Trivial to change this to, say, primes
('', ' | ', @n ).fmt($fmt).say;
('-' x $w, '-+-', '-' x $w xx $max ).fmt($fmt).say;
for @n -> $n {
($n, ' | ', @n.map: { $n > $^m ?? '' !! $n * $^m }).fmt($fmt).say;
}
}
|