aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2025-02-12 18:23:20 +0000
committerGitHub <noreply@github.com>2025-02-12 18:23:20 +0000
commitaf273413c5cbadb34ce8187df7c957de99541ca2 (patch)
treeac63c13de623854c48451bca7581af315252fca9
parentefbbd70096a93d104daa9a42ee390982e0ffbd9b (diff)
parentaa1f475fd09d1c3f03af2216334fd9922a2c8ab2 (diff)
downloadperlweeklychallenge-club-af273413c5cbadb34ce8187df7c957de99541ca2.tar.gz
perlweeklychallenge-club-af273413c5cbadb34ce8187df7c957de99541ca2.tar.bz2
perlweeklychallenge-club-af273413c5cbadb34ce8187df7c957de99541ca2.zip
Merge pull request #11566 from mahnkong/challenge-308
Challenge 308
-rw-r--r--challenge-308/mahnkong/perl/ch-1.pl16
-rw-r--r--challenge-308/mahnkong/perl/ch-2.pl15
2 files changed, 31 insertions, 0 deletions
diff --git a/challenge-308/mahnkong/perl/ch-1.pl b/challenge-308/mahnkong/perl/ch-1.pl
new file mode 100644
index 0000000000..6052e8094a
--- /dev/null
+++ b/challenge-308/mahnkong/perl/ch-1.pl
@@ -0,0 +1,16 @@
+use strict;
+use warnings;
+use feature 'signatures';
+use Test::More 'no_plan';
+
+sub run($str1, $str2) {
+ my %lookup = map { $_ => 1 } @$str2;
+ foreach my $str (@$str1) {
+ delete $lookup{$str} if exists $lookup{$str};
+ }
+ return scalar(@$str2) - scalar(keys(%lookup));
+}
+
+is_deeply(run(["perl", "weekly", "challenge"], ["raku", "weekly", "challenge"]), 2, "Example 1");
+is_deeply(run(["perl", "raku", "python"], ["python", "java"]), 1, "Example 2");
+is_deeply(run(["guest", "contribution"], ["fun", "weekly", "challenge"]), 0, "Example 3");
diff --git a/challenge-308/mahnkong/perl/ch-2.pl b/challenge-308/mahnkong/perl/ch-2.pl
new file mode 100644
index 0000000000..f0d16b30f1
--- /dev/null
+++ b/challenge-308/mahnkong/perl/ch-2.pl
@@ -0,0 +1,15 @@
+use strict;
+use warnings;
+use feature 'signatures';
+use Test::More 'no_plan';
+
+sub run($encoded, $initial) {
+ my $original = [$initial];
+ foreach my $e (@$encoded) {
+ push @$original, $e ^ $original->[-1];
+ }
+ return $original;
+}
+
+is_deeply(run([1, 2, 3], 1), [1, 0, 2, 1], "Example 1");
+is_deeply(run([6, 2, 7, 3], 4), [4, 2, 0, 7, 4], "Example 2");