diff options
| -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"); |
