diff options
| author | Andreas Mahnke <andreas.mahnke@leuphana.de> | 2025-02-11 16:31:24 +0100 |
|---|---|---|
| committer | Andreas Mahnke <andreas.mahnke@leuphana.de> | 2025-02-11 16:31:24 +0100 |
| commit | aa1f475fd09d1c3f03af2216334fd9922a2c8ab2 (patch) | |
| tree | 3530631346ad26d9638c495031541eaf10e6967c | |
| parent | aa4b8399bdb3da0a50173fcab689bfa80b9b54e1 (diff) | |
| download | perlweeklychallenge-club-aa1f475fd09d1c3f03af2216334fd9922a2c8ab2.tar.gz perlweeklychallenge-club-aa1f475fd09d1c3f03af2216334fd9922a2c8ab2.tar.bz2 perlweeklychallenge-club-aa1f475fd09d1c3f03af2216334fd9922a2c8ab2.zip | |
Challenge 308
| -rw-r--r-- | challenge-308/mahnkong/perl/ch-1.pl | 16 | ||||
| -rw-r--r-- | challenge-308/mahnkong/perl/ch-2.pl | 15 |
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"); |
