aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2020-11-23 19:33:52 +0000
committerGitHub <noreply@github.com>2020-11-23 19:33:52 +0000
commitc22198b19c06fac0a983c10b280650376edfff09 (patch)
tree5816d3ce8ace330279c25aa695a48411a0280eeb
parente46baad24ffc93641817f0bdb18cef825871255e (diff)
parentf487deb4626b50b339f478245671b47bd50f64e6 (diff)
downloadperlweeklychallenge-club-c22198b19c06fac0a983c10b280650376edfff09.tar.gz
perlweeklychallenge-club-c22198b19c06fac0a983c10b280650376edfff09.tar.bz2
perlweeklychallenge-club-c22198b19c06fac0a983c10b280650376edfff09.zip
Merge pull request #2831 from drbaggy/master
First pass at ch 88
-rw-r--r--challenge-088/james-smith/perl/ch-1.pl19
-rw-r--r--challenge-088/james-smith/perl/ch-2.pl25
2 files changed, 44 insertions, 0 deletions
diff --git a/challenge-088/james-smith/perl/ch-1.pl b/challenge-088/james-smith/perl/ch-1.pl
new file mode 100644
index 0000000000..117fff074d
--- /dev/null
+++ b/challenge-088/james-smith/perl/ch-1.pl
@@ -0,0 +1,19 @@
+#!/usr/local/bin/perl
+
+use strict;
+
+use warnings;
+use feature qw(say);
+use Test::More;
+
+is( "@{[ prod_list( qw(5 2 1 4 3) ) ]}", '24 60 120 30 40' );
+is( "@{[ prod_list( qw(2 1 4 3) ) ]}", '12 24 6 8' );
+
+done_testing();
+
+sub prod_list {
+ my $N = 1;
+ $N *= $_ foreach @_;
+ return map { $N/$_} @_;
+}
+
diff --git a/challenge-088/james-smith/perl/ch-2.pl b/challenge-088/james-smith/perl/ch-2.pl
new file mode 100644
index 0000000000..3ea3d71715
--- /dev/null
+++ b/challenge-088/james-smith/perl/ch-2.pl
@@ -0,0 +1,25 @@
+#!/usr/local/bin/perl
+
+use strict;
+
+use warnings;
+use feature qw(say);
+use Test::More;
+
+is( "@{ spiral_matrix([1,2,3],[4,5,6],[7,8,9]) }", '1 2 3 6 9 8 7 4 5' );
+is( "@{ spiral_matrix([1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]) }", '1 2 3 4 8 12 16 15 14 13 9 5 6 7 11 10' );
+
+done_testing();
+
+sub spiral_matrix {
+ my @rows = @_;
+ my @res;
+ while(@rows) {
+ push @res, @{shift @rows};
+ push @res, pop @{$_} foreach grep { @{$_} } @rows;
+ push @res, reverse @{ pop @rows } if @rows; ## Make sure we have data!
+ push @res, shift @{$_} foreach grep { @{$_} } reverse @rows;
+ }
+ return \@res;
+}
+