diff options
| author | Steven Wilson <steven1170@zoho.eu> | 2021-11-29 14:37:37 +0000 |
|---|---|---|
| committer | Steven Wilson <steven1170@zoho.eu> | 2021-11-29 14:37:37 +0000 |
| commit | ff461cc6959c56f5ea9d3c044c976121cecbb96f (patch) | |
| tree | e4b215299a425d6effe0fd9189d87e3e28d40639 | |
| parent | a53828c517ea7368d0efc3f64779bd0853c17330 (diff) | |
| download | perlweeklychallenge-club-ff461cc6959c56f5ea9d3c044c976121cecbb96f.tar.gz perlweeklychallenge-club-ff461cc6959c56f5ea9d3c044c976121cecbb96f.tar.bz2 perlweeklychallenge-club-ff461cc6959c56f5ea9d3c044c976121cecbb96f.zip | |
add solution week 140 task 2 in perl
| -rw-r--r-- | challenge-140/steven-wilson/perl/ch-2.pl | 35 |
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]\"."; + |
