aboutsummaryrefslogtreecommitdiff
path: root/challenge-033
diff options
context:
space:
mode:
authorSimon Proctor <simon.proctor@zpg.co.uk>2019-11-04 12:15:30 +0000
committerSimon Proctor <simon.proctor@zpg.co.uk>2019-11-04 12:15:30 +0000
commit2c2940d5ff2d948c3d0953270e9140e5e1204f3f (patch)
tree1484ef305b8baf56dfbd867e02a91478df279fdb /challenge-033
parent4dc5e0b7b1f170236ebaa940ede9d804dea49614 (diff)
downloadperlweeklychallenge-club-2c2940d5ff2d948c3d0953270e9140e5e1204f3f.tar.gz
perlweeklychallenge-club-2c2940d5ff2d948c3d0953270e9140e5e1204f3f.tar.bz2
perlweeklychallenge-club-2c2940d5ff2d948c3d0953270e9140e5e1204f3f.zip
Display the multiplication table up to 11
Diffstat (limited to 'challenge-033')
-rw-r--r--challenge-033/simon-proctor/perl6/ch-2.p628
1 files changed, 28 insertions, 0 deletions
diff --git a/challenge-033/simon-proctor/perl6/ch-2.p6 b/challenge-033/simon-proctor/perl6/ch-2.p6
new file mode 100644
index 0000000000..1789f98ab9
--- /dev/null
+++ b/challenge-033/simon-proctor/perl6/ch-2.p6
@@ -0,0 +1,28 @@
+#!/usr/bin/env perl6
+
+use v6;
+
+my %*SUB-MAIN-OPTS = :named-anywhere;
+
+#| Print help text
+multi sub MAIN( Bool :h($help) where so * ) {
+ say $*USAGE;
+}
+
+#| Print the times table up to 11
+multi sub MAIN() {
+ .say for get-header();
+ .say for (1..11).map( { get-row($_) } );
+}
+
+sub format-row( *@data ) {
+ sprintf " %2s | %3s %3s %3s %3s %3s %3s %3s %3s %3s %3s %3s", @data;
+}
+
+sub get-header() {
+ ( format-row( "x", |(1..11) ), "-" x 49 );
+}
+
+sub get-row( $val ) {
+ format-row( $val, |( "" xx $val-1 ), |($val..11).map( * * $val ) );
+}