diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2025-07-12 00:21:18 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-12 00:21:18 +0100 |
| commit | 3e11cdc36cd5e183b532824378a4cb8230e207ad (patch) | |
| tree | 75eb3fdd2ae7b5547c6469477ddeca4d6c3c38aa | |
| parent | 416e96fc2b3e5ef01a2fd7bc3107b19f88f1f767 (diff) | |
| parent | 46c3889bd08b7de73f04671f390b888a2dfb7ccf (diff) | |
| download | perlweeklychallenge-club-3e11cdc36cd5e183b532824378a4cb8230e207ad.tar.gz perlweeklychallenge-club-3e11cdc36cd5e183b532824378a4cb8230e207ad.tar.bz2 perlweeklychallenge-club-3e11cdc36cd5e183b532824378a4cb8230e207ad.zip | |
Merge pull request #12323 from mahnkong/challenge-329
Challenge 329
| -rw-r--r-- | challenge-329/mahnkong/perl/ch-1.pl | 16 | ||||
| -rw-r--r-- | challenge-329/mahnkong/perl/ch-2.pl | 22 |
2 files changed, 38 insertions, 0 deletions
diff --git a/challenge-329/mahnkong/perl/ch-1.pl b/challenge-329/mahnkong/perl/ch-1.pl new file mode 100644 index 0000000000..ca15d67c83 --- /dev/null +++ b/challenge-329/mahnkong/perl/ch-1.pl @@ -0,0 +1,16 @@ +use strict; +use warnings; +use feature 'signatures'; +use Test::More 'no_plan'; + +sub run($str) { + my @result; + while ($str =~ /(\d+)/g) { + push @result, $1 unless grep /^$1$/, @result; + } + return [ @result ]; +} + +is_deeply(run('the1weekly2challenge2'), [1, 2], "Example 1"); +is_deeply(run('go21od1lu5c7k'), [21, 1, 5, 7], "Example 2"); +is_deeply(run('4p3e2r1l'), [4, 3, 2, 1], "Example 3"); diff --git a/challenge-329/mahnkong/perl/ch-2.pl b/challenge-329/mahnkong/perl/ch-2.pl new file mode 100644 index 0000000000..a5bfed49ff --- /dev/null +++ b/challenge-329/mahnkong/perl/ch-2.pl @@ -0,0 +1,22 @@ +use strict; +use warnings; +use feature 'signatures'; +use Test::More 'no_plan'; + +sub run($str) { + my $longest = ""; + + for my $c ("a" .. "z") { + my $uc = uc($c); + while ($str =~ /($c+)/gi) { + my $m = $1; + $longest = $m if $m =~ /$c/ && $m =~ /$uc/ && length($m) > length($longest); + } + } + return $longest; +} + +is(run("YaaAho"), "aaA", "Example 1"); +is(run("cC"), "cC", "Example 2"); +is(run("A"), "", "Example 3"); +is(run("cCaaaa"), "cC", "Example 4"); |
