aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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");