diff options
| -rw-r--r-- | challenge-341/mahnkong/perl/ch-1.pl | 19 | ||||
| -rw-r--r-- | challenge-341/mahnkong/perl/ch-2.pl | 16 |
2 files changed, 35 insertions, 0 deletions
diff --git a/challenge-341/mahnkong/perl/ch-1.pl b/challenge-341/mahnkong/perl/ch-1.pl new file mode 100644 index 0000000000..304b88c9e2 --- /dev/null +++ b/challenge-341/mahnkong/perl/ch-1.pl @@ -0,0 +1,19 @@ +use strict; +use warnings; +use feature 'signatures'; +use Test::More 'no_plan'; + +sub run($string, $keys) { + my $result = 0; + my $keys_str = join('', @$keys); + foreach my $word (split(' ', $string)) { + $result += 1 if $word =~ /^[^ $keys_str]+$/i; + } + return $result; +} + +is(run("Hello World", ['d']), 1, "Example 1"); +is(run("apple banana cherry", ['a','e']), 0, "Example 2"); +is(run("Coding is fun", []), 3, "Example 3"); +is(run("The Weekly Challenge", ['a', 'b']), 2, "Example 4"); +is(run("Perl and Python", ['p']), 1, "Example 5"); diff --git a/challenge-341/mahnkong/perl/ch-2.pl b/challenge-341/mahnkong/perl/ch-2.pl new file mode 100644 index 0000000000..118e2fa118 --- /dev/null +++ b/challenge-341/mahnkong/perl/ch-2.pl @@ -0,0 +1,16 @@ +use strict; +use warnings; +use feature 'signatures'; +use Test::More 'no_plan'; + +sub run($string, $char) { + my $pos = index($string, $char); + return $string if $pos == -1; + return (reverse(substr($string, 0, $pos+1))) . substr($string, $pos+1, length($string)); +} + +is(run("programming", "g"), "gorpramming", "Example 1"); +is(run("hello", "h"), "hello", "Example 2"); +is(run("abcdefghij", "h"), "hgfedcbaij", "Example 3"); +is(run("reverse", "s"), "srevere", "Example 4"); +is(run("perl", "r"), "repl", "Example 5"); |
