From aa1f475fd09d1c3f03af2216334fd9922a2c8ab2 Mon Sep 17 00:00:00 2001 From: Andreas Mahnke Date: Tue, 11 Feb 2025 16:31:24 +0100 Subject: Challenge 308 --- challenge-308/mahnkong/perl/ch-1.pl | 16 ++++++++++++++++ challenge-308/mahnkong/perl/ch-2.pl | 15 +++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 challenge-308/mahnkong/perl/ch-1.pl create mode 100644 challenge-308/mahnkong/perl/ch-2.pl 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"); -- cgit