diff options
| author | Andreas Mahnke <andreas.mahnke@leuphana.de> | 2025-07-04 15:09:57 +0200 |
|---|---|---|
| committer | Andreas Mahnke <andreas.mahnke@leuphana.de> | 2025-07-04 15:09:57 +0200 |
| commit | a3a2a6a1e85808f786a52994e172409069bdcae6 (patch) | |
| tree | af8214142ae1f6b852a7226fe4a9f0ccd812b486 | |
| parent | 7daf92e1dd4a2726fc578e87b6364ba4db3d5ad9 (diff) | |
| download | perlweeklychallenge-club-a3a2a6a1e85808f786a52994e172409069bdcae6.tar.gz perlweeklychallenge-club-a3a2a6a1e85808f786a52994e172409069bdcae6.tar.bz2 perlweeklychallenge-club-a3a2a6a1e85808f786a52994e172409069bdcae6.zip | |
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"); |
