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