aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2025-06-24 23:45:18 +0100
committerGitHub <noreply@github.com>2025-06-24 23:45:18 +0100
commit83f83dde4ce269c0f7ee7f2a0fc7488bbf459eef (patch)
treef6c7996aa8bd194ad2fa07830c1d8dc2e5c7a252
parente363f25dc95d7ca638480ec22e092ebc0f100cdc (diff)
parentda89c0ca85231a9efb0216cdb975d08fd1f583ff (diff)
downloadperlweeklychallenge-club-83f83dde4ce269c0f7ee7f2a0fc7488bbf459eef.tar.gz
perlweeklychallenge-club-83f83dde4ce269c0f7ee7f2a0fc7488bbf459eef.tar.bz2
perlweeklychallenge-club-83f83dde4ce269c0f7ee7f2a0fc7488bbf459eef.zip
Merge pull request #12230 from zapwai/branch-for-327
Week 327
-rw-r--r--challenge-327/zapwai/perl/ch-1.pl16
-rw-r--r--challenge-327/zapwai/perl/ch-2.pl40
2 files changed, 56 insertions, 0 deletions
diff --git a/challenge-327/zapwai/perl/ch-1.pl b/challenge-327/zapwai/perl/ch-1.pl
new file mode 100644
index 0000000000..a5a189975e
--- /dev/null
+++ b/challenge-327/zapwai/perl/ch-1.pl
@@ -0,0 +1,16 @@
+use v5.38;
+
+sub proc(@ints) {
+ say "Input: @ints";
+ my @o = grep {!($_ ~~ @ints)} (1 .. @ints);
+ say "Output: @o";
+}
+
+my @ints = (1,2,1,3,2,5);
+proc(@ints);
+@ints = (1,1,1);
+proc(@ints);
+@ints = (2,2,1);
+proc(@ints);
+@ints = (2,1);
+proc(@ints);
diff --git a/challenge-327/zapwai/perl/ch-2.pl b/challenge-327/zapwai/perl/ch-2.pl
new file mode 100644
index 0000000000..01d03cd59c
--- /dev/null
+++ b/challenge-327/zapwai/perl/ch-2.pl
@@ -0,0 +1,40 @@
+use v5.38;
+
+sub mad(@ints) {
+ my $min = abs($ints[1] - $ints[0]);
+ for my $i (0 .. $#ints - 1) {
+ for my $j ($i + 1 .. $#ints) {
+ my $diff = abs($ints[$i] - $ints[$j]);
+ $min = $diff if ($min > $diff);
+ }
+ }
+ my @out;
+ for my $i (0 .. $#ints - 1) {
+ for my $j ($i + 1 .. $#ints) {
+ my $diff = abs($ints[$i] - $ints[$j]);
+ if ($diff == $min) {
+ if ($ints[$i] < $ints[$j]) {
+ push @out, [$ints[$i], $ints[$j]];
+ } else {
+ push @out, [$ints[$j], $ints[$i]];
+ }
+ }
+ }
+ }
+ return @out;
+}
+
+sub proc(@ints) {
+ say "Input: @ints";
+ my @o = mad(@ints);
+ print "Output: ";
+ print "(". join(", ", @$_) . ") " for (@o);
+ say "";
+}
+
+my @ints = (4,1,2,3);
+proc(@ints);
+@ints = (1,3,7,11,15);
+proc(@ints);
+@ints = (1,5,3,8);
+proc(@ints);