aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2022-12-20 09:27:01 +0000
committerGitHub <noreply@github.com>2022-12-20 09:27:01 +0000
commit7c61e50191c9ea07177c660ff3214d358c759411 (patch)
tree5f160a730b36916576735374774745354cae64f2
parent80b02f0b8318ed6894e5f80f8fce6df973288d44 (diff)
parent678ee3b1fabdf844938495b670377ff31e03f926 (diff)
downloadperlweeklychallenge-club-7c61e50191c9ea07177c660ff3214d358c759411.tar.gz
perlweeklychallenge-club-7c61e50191c9ea07177c660ff3214d358c759411.tar.bz2
perlweeklychallenge-club-7c61e50191c9ea07177c660ff3214d358c759411.zip
Merge pull request #7283 from zapwai/branch-for-challenge-196
Week 196
-rw-r--r--challenge-196/zapwai/perl/ch-1.pl28
-rw-r--r--challenge-196/zapwai/perl/ch-2.pl30
2 files changed, 58 insertions, 0 deletions
diff --git a/challenge-196/zapwai/perl/ch-1.pl b/challenge-196/zapwai/perl/ch-1.pl
new file mode 100644
index 0000000000..f7eb7356c5
--- /dev/null
+++ b/challenge-196/zapwai/perl/ch-1.pl
@@ -0,0 +1,28 @@
+#!/usr/bin/env perl
+my @list;
+my @testlist = ( [3,1,4,2],
+ [1,2,3,4],
+ [1,3,2,4,6,5],
+ [1,3,4,2],
+ );
+for (@testlist) {
+ @list = @{$_};
+ driver();
+}
+sub driver {
+ print "Input: (".join(",",@list).")\n";
+ print "Output: ";
+
+ for my $i (0 .. $#list - 2) {
+ for my $j ($i + 1 .. $#list -1) {
+ for my $k ($j + 1 .. $#list) {
+ if ( ($list[$i] < $list[$k]) &&
+ ($list[$k] < $list[$j]) ) {
+ print "(", join(",",@list[$i, $j, $k]), ")\n";
+ return;
+ }
+ }
+ }
+ }
+ print "()\n";
+}
diff --git a/challenge-196/zapwai/perl/ch-2.pl b/challenge-196/zapwai/perl/ch-2.pl
new file mode 100644
index 0000000000..640b34688e
--- /dev/null
+++ b/challenge-196/zapwai/perl/ch-2.pl
@@ -0,0 +1,30 @@
+#!/usr/bin/env perl
+my @list1 = (1,3,4,5,7);
+my @list2 = (1,2,3,6,7,9);
+my @list3 = (0,1,2,4,5,6,8,9);
+my @lists = (\@list1, \@list2, \@list3);
+
+for my $ref (@lists) {
+ my @list = @{$ref};
+ print "Input: (".join(",",@list).")\n";
+ print "Output: ";
+
+ my $range_flag = 0;
+ my $comma_flag = 0;
+ for my $index (0 .. $#list) {
+ if ($list[$index + 1] == $list[$index] + 1) {
+ if (!$range_flag) {
+ $range_flag = 1;
+ print ", " if ($comma_flag);
+ print "[$list[$index],";
+ }
+ } else {
+ if ($range_flag) {
+ $range_flag = 0;
+ $comma_flag = 1;
+ print "$list[$index]]";
+ }
+ }
+ }
+ print "\n";
+}