diff options
| author | Andreas Mahnke <andreas.mahnke@leuphana.de> | 2025-10-20 11:22:39 +0200 |
|---|---|---|
| committer | Andreas Mahnke <andreas.mahnke@leuphana.de> | 2025-10-20 11:22:39 +0200 |
| commit | fc39806737cffcdd08dbaab72e24ac6d0b7f688b (patch) | |
| tree | e9980dfb3574cf785c3fb275d9b93cdaea16a0cd | |
| parent | 0089e40542c8edad54c99aad1b7e01bfe7050231 (diff) | |
| download | perlweeklychallenge-club-fc39806737cffcdd08dbaab72e24ac6d0b7f688b.tar.gz perlweeklychallenge-club-fc39806737cffcdd08dbaab72e24ac6d0b7f688b.tar.bz2 perlweeklychallenge-club-fc39806737cffcdd08dbaab72e24ac6d0b7f688b.zip | |
Challenge 344
| -rw-r--r-- | challenge-344/mahnkong/perl/ch-1.pl | 14 | ||||
| -rw-r--r-- | challenge-344/mahnkong/perl/ch-2.pl | 18 |
2 files changed, 32 insertions, 0 deletions
diff --git a/challenge-344/mahnkong/perl/ch-1.pl b/challenge-344/mahnkong/perl/ch-1.pl new file mode 100644 index 0000000000..9f8f21e5ff --- /dev/null +++ b/challenge-344/mahnkong/perl/ch-1.pl @@ -0,0 +1,14 @@ +use strict; +use warnings; +use feature 'signatures'; +use Test::More 'no_plan'; + +sub run($ints, $x) { + return [ split("", join('', @$ints) + $x) ]; +} + +is_deeply(run([1,2,3,4], 12), [1,2,4,6], "Example 1"); +is_deeply(run([2,7,4], 181), [4,5,5], "Example 2"); +is_deeply(run([9,9,9], 1), [1,0,0,0], "Example 3"); +is_deeply(run([1,0,0,0,0], 9999), [1,9,9,9,9], "Example 4"); +is_deeply(run([0], 1000), [1,0,0,0], "Example 5"); diff --git a/challenge-344/mahnkong/perl/ch-2.pl b/challenge-344/mahnkong/perl/ch-2.pl new file mode 100644 index 0000000000..555402a506 --- /dev/null +++ b/challenge-344/mahnkong/perl/ch-2.pl @@ -0,0 +1,18 @@ +use strict; +use warnings; +use feature 'signatures'; +use Test::More 'no_plan'; + +sub run($source, $target) { + my $target_string = join("", @$target); + foreach my $string (map { join ("", @{$_}) } @$source) { + $target_string =~ s/$string//; + } + return length($target_string) == 0 ? 1 : 0; +} + +is(run([[2,3], [1], [4]], [1, 2, 3, 4]), 1, "Example 1"); +is(run([[1,3], [2,4]], [1, 2, 3, 4]), 0, "Example 2"); +is(run([[9,1], [5,8], [2]], [5, 8, 2, 9, 1]), 1, "Example 3"); +is(run([[1], [3]], [1, 2, 3]), 0, "Example 4"); +is(run([[7,4,6]], [7, 4, 6]), 1, "Example 5"); |
