diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2025-07-04 17:12:08 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-04 17:12:08 +0100 |
| commit | 17af0b14baab39fe438f7c050579de75e1fb79e1 (patch) | |
| tree | f2d7583b43388c5a5248c38da63e1f573fa95613 | |
| parent | 5ea606f19ac8c1dfa89419f67b0f0989fd0fad79 (diff) | |
| parent | a3a2a6a1e85808f786a52994e172409069bdcae6 (diff) | |
| download | perlweeklychallenge-club-17af0b14baab39fe438f7c050579de75e1fb79e1.tar.gz perlweeklychallenge-club-17af0b14baab39fe438f7c050579de75e1fb79e1.tar.bz2 perlweeklychallenge-club-17af0b14baab39fe438f7c050579de75e1fb79e1.zip | |
Merge pull request #12280 from mahnkong/challenge-328
Challenge 328
| -rw-r--r-- | challenge-328/mahnkong/perl/ch-1.pl | 30 | ||||
| -rw-r--r-- | challenge-328/mahnkong/perl/ch-2.pl | 26 |
2 files changed, 56 insertions, 0 deletions
diff --git a/challenge-328/mahnkong/perl/ch-1.pl b/challenge-328/mahnkong/perl/ch-1.pl new file mode 100644 index 0000000000..52f827fc36 --- /dev/null +++ b/challenge-328/mahnkong/perl/ch-1.pl @@ -0,0 +1,30 @@ +use strict; +use warnings; +use feature 'signatures'; +use Test::More 'no_plan'; + +sub run($str) { + my @str = split //, $str; + my @chars; + push @chars, $_ for ("a" .. "z"); + + for (my $i = 0; $i < scalar(@str); $i++) { + if ($str[$i] eq '?') { + foreach my $s (@chars) { + unless (($str[$i - 1] && $str[$i - 1] eq $s) || ($str[$i + 1] && $str[$i + 1] eq $s)) { + $str[$i] = $s; + last + } + } + next; + } + } + return join('', @str); +} + +is(run('a?z'), 'abz', "Example 1"); +is(run('pe?k'), 'peak', "Example 2"); +is(run('pe??k'), 'peabk', "Example 3"); +is(run('gra?te'), 'grabte', "Example 4"); +is(run('gra?t?e'), 'grabtae', "Example 5"); +is(run('c????b?'), 'cabacba', "Example 6"); diff --git a/challenge-328/mahnkong/perl/ch-2.pl b/challenge-328/mahnkong/perl/ch-2.pl new file mode 100644 index 0000000000..8a1ceb467a --- /dev/null +++ b/challenge-328/mahnkong/perl/ch-2.pl @@ -0,0 +1,26 @@ +use strict; +use warnings; +use feature 'signatures'; +use Test::More 'no_plan'; + +sub run($string) { + while (1) { + my $modified = 0; + for my $c ("a" .. "z") { + foreach my $v (uc($c).$c, $c.uc($c)) { + if ($string =~ /$v/) { + $string =~ s/$v//; + $modified = 1; + last; + } + } + last if $modified; + } + last unless $modified; + } + return $string; +} + +is(run("WeEeekly"), "Weekly", "Example 1"); +is(run("abBAdD"), "", "Example 2"); +is(run("abc"), "abc", "Example 3"); |
