aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2025-08-11 00:22:57 +0100
committerGitHub <noreply@github.com>2025-08-11 00:22:57 +0100
commitb3d61dcc00dc21a997af9a4c9d8de69fba311062 (patch)
tree02835661de6633bd3c436a29adbd0f44b3183487
parent3022cc2fa0c84215c17f9b3bf508ea5ff0ea0b06 (diff)
parentaf44daaeb7d257a1077fd2095fdf9d69b0649d0b (diff)
downloadperlweeklychallenge-club-b3d61dcc00dc21a997af9a4c9d8de69fba311062.tar.gz
perlweeklychallenge-club-b3d61dcc00dc21a997af9a4c9d8de69fba311062.tar.bz2
perlweeklychallenge-club-b3d61dcc00dc21a997af9a4c9d8de69fba311062.zip
Merge pull request #12492 from mahnkong/challenge-332_333
Challenges 332 and 333
-rw-r--r--challenge-332/mahnkong/perl/ch-1.pl15
-rw-r--r--challenge-332/mahnkong/perl/ch-2.pl18
-rw-r--r--challenge-333/mahnkong/perl/ch-1.pl27
-rw-r--r--challenge-333/mahnkong/perl/ch-2.pl22
4 files changed, 82 insertions, 0 deletions
diff --git a/challenge-332/mahnkong/perl/ch-1.pl b/challenge-332/mahnkong/perl/ch-1.pl
new file mode 100644
index 0000000000..9862eb6b68
--- /dev/null
+++ b/challenge-332/mahnkong/perl/ch-1.pl
@@ -0,0 +1,15 @@
+use strict;
+use warnings;
+use feature 'signatures';
+use Test::More 'no_plan';
+
+sub run($str) {
+ if ($str =~ /(\d{4})-(\d{2})-(\d{2})/) {
+ return sprintf("%b-%b-%b", $1, $2, $3);
+ }
+ return undef;
+}
+
+is(run('2025-07-26'), '11111101001-111-11010', "Example 1");
+is(run('2000-02-02'), '11111010000-10-10', "Example 2");
+is(run('2024-12-31'), '11111101000-1100-11111', "Example 3");
diff --git a/challenge-332/mahnkong/perl/ch-2.pl b/challenge-332/mahnkong/perl/ch-2.pl
new file mode 100644
index 0000000000..dfaa7c6ff1
--- /dev/null
+++ b/challenge-332/mahnkong/perl/ch-2.pl
@@ -0,0 +1,18 @@
+use strict;
+use warnings;
+use feature 'signatures';
+use Test::More 'no_plan';
+
+sub run($string) {
+ return undef unless $string;
+ my %occurences;
+ for my $c (split //, $string) {
+ $occurences{$c} += 1;
+ }
+ my @sorted = sort { $b <=> $a } values(%occurences);
+ return $sorted[0] == 1 ? 1 : 0;
+}
+
+is(run("weekly"), 0, "Example 1");
+is(run("perl"), 1, "Example 2");
+is(run("challenge"), 0, "Example 3");
diff --git a/challenge-333/mahnkong/perl/ch-1.pl b/challenge-333/mahnkong/perl/ch-1.pl
new file mode 100644
index 0000000000..72c77eff46
--- /dev/null
+++ b/challenge-333/mahnkong/perl/ch-1.pl
@@ -0,0 +1,27 @@
+use strict;
+use warnings;
+use feature 'signatures';
+use Test::More 'no_plan';
+
+sub run(@coordinates) {
+ my $diff_x;
+ my $diff_y;
+
+ return 1 if scalar(@coordinates) < 2;
+
+ my ($x0, $y0) = @{$coordinates[0]};
+ my ($x1, $y1) = @{$coordinates[1]};
+
+ for (my $i = 2; $i < scalar(@coordinates); $i++) {
+ my ($x, $y) = @{$coordinates[$i]};
+
+ return 0 if ($y1-$y0)*($x-$x0) != ($y-$y0)*($x1-$x0);
+ }
+ return 1;
+}
+
+is(run([2, 1], [2, 3], [2, 5]), 1, "Example 1");
+is(run([1, 4], [3, 4], [10, 4]), 1, "Example 2");
+is(run([0, 0], [1, 1], [2, 3]), 0, "Example 3");
+is(run([1, 1], [1, 1], [1, 1]), 1, "Example 4");
+is(run([1000000, 1000000], [2000000, 2000000], [3000000, 3000000]), 1, "Example 5");
diff --git a/challenge-333/mahnkong/perl/ch-2.pl b/challenge-333/mahnkong/perl/ch-2.pl
new file mode 100644
index 0000000000..cd30b46d4a
--- /dev/null
+++ b/challenge-333/mahnkong/perl/ch-2.pl
@@ -0,0 +1,22 @@
+use strict;
+use warnings;
+use feature 'signatures';
+use Test::More 'no_plan';
+
+sub run(@ints) {
+ for (my $i = 0; $i <= $#ints; $i++) {
+ if ($ints[$i] == 0 && exists($ints[$i + 1])) {
+ for (my $j = $#ints; $j > $i; $j--) {
+ $ints[$j] = $ints[$j-1];
+ }
+ $i+=1;
+ }
+ }
+ return \@ints;
+}
+
+is_deeply(run(1, 0, 2, 3, 0, 4, 5, 0), [1, 0, 0, 2, 3, 0, 0, 4], "Example 1");
+is_deeply(run(1, 2, 3), [1, 2, 3], "Example 2");
+is_deeply(run(1, 2, 3, 0), [1, 2, 3, 0], "Example 3");
+is_deeply(run(0, 0, 1, 2), [0, 0, 0, 0], "Example 4");
+is_deeply(run(1, 2, 0, 3, 4), [1, 2, 0, 0, 3], "Example 5");