diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2025-09-29 22:51:26 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-09-29 22:51:26 +0100 |
| commit | 0712592627137bf53d2b18978df893099d2133a2 (patch) | |
| tree | ddd0393917824e1679e6a9c0d16330842a7b2363 | |
| parent | 4b8444c1b5a8c11fee7f3343700add87acc5c81a (diff) | |
| parent | 48fa26a98288d4756e78849dc808bca98e3e6199 (diff) | |
| download | perlweeklychallenge-club-0712592627137bf53d2b18978df893099d2133a2.tar.gz perlweeklychallenge-club-0712592627137bf53d2b18978df893099d2133a2.tar.bz2 perlweeklychallenge-club-0712592627137bf53d2b18978df893099d2133a2.zip | |
Merge pull request #12760 from mahnkong/challenge-341
Challenge 341
| -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"); |
