aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-04-01 00:49:52 +0100
committerGitHub <noreply@github.com>2024-04-01 00:49:52 +0100
commite30ac45a8c0f9852aa17ff2264cc813c83cbaf9f (patch)
treee0405d8a9c212bec2afb82917344e7a66ed4dbe8
parent40e6fa6bcc9a3abe07a6b8cf89cad2e5741b221b (diff)
parent7592a868df05ecb400eccebe7b9705bfe3fad48d (diff)
downloadperlweeklychallenge-club-e30ac45a8c0f9852aa17ff2264cc813c83cbaf9f.tar.gz
perlweeklychallenge-club-e30ac45a8c0f9852aa17ff2264cc813c83cbaf9f.tar.bz2
perlweeklychallenge-club-e30ac45a8c0f9852aa17ff2264cc813c83cbaf9f.zip
Merge pull request #9843 from E7-87-83/newt
Week 262
-rw-r--r--challenge-262/cheok-yin-fung/perl/ch-1.pl17
-rw-r--r--challenge-262/cheok-yin-fung/perl/ch-2.pl21
2 files changed, 38 insertions, 0 deletions
diff --git a/challenge-262/cheok-yin-fung/perl/ch-1.pl b/challenge-262/cheok-yin-fung/perl/ch-1.pl
new file mode 100644
index 0000000000..a072bfc8d4
--- /dev/null
+++ b/challenge-262/cheok-yin-fung/perl/ch-1.pl
@@ -0,0 +1,17 @@
+# The Weekly Challenge 262
+# Task 1 Max Positive Negative
+use v5.30.0;
+use warnings;
+
+sub mpn {
+ my @ints = @_;
+ my $p = grep {$_ > 0} @ints;
+ my $n = grep {$_ < 0} @ints;
+ return $p > $n ? $p : $n;
+}
+
+use Test::More tests=>4;
+ok mpn(-3, 1, 2, -1, 3, -2, 4) == 4;
+ok mpn(-1,-2,-3, 1) == 3;
+ok mpn(1,2) == 2;
+ok mpn(0,0,0) == 0;
diff --git a/challenge-262/cheok-yin-fung/perl/ch-2.pl b/challenge-262/cheok-yin-fung/perl/ch-2.pl
new file mode 100644
index 0000000000..5999690579
--- /dev/null
+++ b/challenge-262/cheok-yin-fung/perl/ch-2.pl
@@ -0,0 +1,21 @@
+# The Weekly Challenge 262
+# Task 2 Count Equal Divisible
+use v5.30.0;
+use warnings;
+
+sub ced {
+ my @ints = $_[0]->@*;
+ my $k = $_[1];
+ my $count = 0;
+ for my $i (0..$#ints-1) {
+ for my $j ($i+1..$#ints) {
+ $count++ if $ints[$i] == $ints[$j] && ($i*$j % $k == 0);
+ }
+ }
+ return $count;
+}
+
+use Test::More tests=>3;
+ok ced([3,1,2,2,2,1,3], 2) == 4;
+ok ced([1,2,3], 1) == 0;
+ok ced([1,2,1], 1) == 1;