aboutsummaryrefslogtreecommitdiff
path: root/challenge-100
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2021-02-16 21:54:08 +0000
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2021-02-16 21:54:08 +0000
commitf6c38ffc79b16b61790647bcfd1af0803d1aa78c (patch)
treeccf6cf13975f7303a8f9cd2e11205f51ef590cbc /challenge-100
parentcbd68f93a19d90e144eea3fc25a2af68b362d036 (diff)
downloadperlweeklychallenge-club-f6c38ffc79b16b61790647bcfd1af0803d1aa78c.tar.gz
perlweeklychallenge-club-f6c38ffc79b16b61790647bcfd1af0803d1aa78c.tar.bz2
perlweeklychallenge-club-f6c38ffc79b16b61790647bcfd1af0803d1aa78c.zip
- Added Perl solution to task 2 of week 100.
Diffstat (limited to 'challenge-100')
-rw-r--r--challenge-100/mohammad-anwar/perl/ch-2.pl30
1 files changed, 30 insertions, 0 deletions
diff --git a/challenge-100/mohammad-anwar/perl/ch-2.pl b/challenge-100/mohammad-anwar/perl/ch-2.pl
new file mode 100644
index 0000000000..6004c09e43
--- /dev/null
+++ b/challenge-100/mohammad-anwar/perl/ch-2.pl
@@ -0,0 +1,30 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More;
+
+is(sum([[1], [2,4], [6,4,9], [5,1,7,2]]), 8);
+is(sum([[3], [3,1], [5,2,3], [4,3,1,3]]), 7);
+
+done_testing;
+
+sub sum {
+ my ($t) = @_;
+
+ my $i = 0;
+ my $s = [ $t->[0]->[$i] ];
+ shift @$t;
+ foreach my $r (@$t) {
+ push @$s,
+ ($r->[$i] > $r->[$i+1])
+ ?($i+=2 and $r->[--$i])
+ :($r->[$i]);
+ }
+
+ my $sum = 0;
+ $sum += $_ for @$s;
+
+ return $sum;
+}