aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-11-29 15:54:55 +0000
committerGitHub <noreply@github.com>2021-11-29 15:54:55 +0000
commit1ada910b34ca3d5200e31c2beef0c8c2e2772401 (patch)
treee4b215299a425d6effe0fd9189d87e3e28d40639
parenta53828c517ea7368d0efc3f64779bd0853c17330 (diff)
parentff461cc6959c56f5ea9d3c044c976121cecbb96f (diff)
downloadperlweeklychallenge-club-1ada910b34ca3d5200e31c2beef0c8c2e2772401.tar.gz
perlweeklychallenge-club-1ada910b34ca3d5200e31c2beef0c8c2e2772401.tar.bz2
perlweeklychallenge-club-1ada910b34ca3d5200e31c2beef0c8c2e2772401.zip
Merge pull request #5307 from oWnOIzRi/week140
add solution week 140 task 2 in perl
-rw-r--r--challenge-140/steven-wilson/perl/ch-2.pl35
1 files changed, 35 insertions, 0 deletions
diff --git a/challenge-140/steven-wilson/perl/ch-2.pl b/challenge-140/steven-wilson/perl/ch-2.pl
new file mode 100644
index 0000000000..00bc221751
--- /dev/null
+++ b/challenge-140/steven-wilson/perl/ch-2.pl
@@ -0,0 +1,35 @@
+#!/usr/bin/env perl
+# Week 140 Task 2
+# Multiplication Table
+
+use strict;
+use warnings;
+use feature qw/ say /;
+use Lingua::EN::Numbers::Ordinate;
+
+my ( $i, $j, $k ) = @ARGV;
+my @rows;
+
+for ( my $y = 1; $y <= $i; $y++ ) {
+ my @row;
+ for ( my $x = 1; $x <= $j; $x++ ) {
+
+ push @row, ( $x * $y );
+ }
+ push @rows, \@row;
+}
+
+my @multiples;
+map { push @multiples, @{$_} } @rows;
+my @sorted_multiples = sort @multiples;
+
+say "Input: \$i = $i, \$j = $j, \$k = $k";
+say "Output: $sorted_multiples[$k-1]\n";
+say "Since the multiplication of $i x $j is as below:\n";
+map { say "\t" . join " ", @{$_} } @rows;
+say "\nThe sorted multiplication table:\n";
+say "\t" . join " ", @sorted_multiples;
+say "\nNow the "
+ . ordinate($k)
+ . " element in the table is \"$sorted_multiples[$k-1]\".";
+