From ab803081e3008647de2b5925ca82f627a85372c0 Mon Sep 17 00:00:00 2001 From: Daniel Mita Date: Sun, 10 Nov 2019 22:04:43 +0000 Subject: Add Raku solution for challenge-033-2 --- challenge-033/daniel-mita/perl6/ch-2.p6 | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 challenge-033/daniel-mita/perl6/ch-2.p6 diff --git a/challenge-033/daniel-mita/perl6/ch-2.p6 b/challenge-033/daniel-mita/perl6/ch-2.p6 new file mode 100755 index 0000000000..a91912a2e4 --- /dev/null +++ b/challenge-033/daniel-mita/perl6/ch-2.p6 @@ -0,0 +1,28 @@ +#!/usr/bin/env perl6 + +#| Prints a multiplication table with only the top half of the triangle +sub MAIN ( + Int $max where * > 0 = 11, #= The max number of the multiplication table (defaults to 11) + --> Nil +) { + my @range = 1 .. $max; + my $spacing = @range[*-1]².chars + 1; + + print ' x|'; + print sprintf('%' ~ $spacing ~ 's', $_) for @range; + print "\n"; + print '--+'; + say [x] « + - + $spacing + @range.elems() + »; + + for @range -> $a { + print sprintf('%2s|', $a); + for @range -> $b { + print sprintf('%' ~ $spacing ~ 's', $a ≤ $b ?? $a * $b !! ''); + } + print "\n"; + } +} -- cgit