diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2025-07-04 09:44:51 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-04 09:44:51 +0100 |
| commit | cf85e2f150d17e305e1ece4004af81b3cea51f26 (patch) | |
| tree | 5a3f5fa7ac7895206cee36b5a2951481b518fc14 | |
| parent | 208bcdbf18ff1a335b8129fccf9c71b460d143f0 (diff) | |
| parent | 1d697380378cf811bb6163ebb46611f1b4688c5d (diff) | |
| download | perlweeklychallenge-club-cf85e2f150d17e305e1ece4004af81b3cea51f26.tar.gz perlweeklychallenge-club-cf85e2f150d17e305e1ece4004af81b3cea51f26.tar.bz2 perlweeklychallenge-club-cf85e2f150d17e305e1ece4004af81b3cea51f26.zip | |
Merge pull request #12277 from wlmb/challenges
Solve PWC328
| -rw-r--r-- | challenge-328/wlmb/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-328/wlmb/perl/ch-1.pl | 24 | ||||
| -rwxr-xr-x | challenge-328/wlmb/perl/ch-2.pl | 17 |
3 files changed, 42 insertions, 0 deletions
diff --git a/challenge-328/wlmb/blog.txt b/challenge-328/wlmb/blog.txt new file mode 100644 index 0000000000..5ed44b71c3 --- /dev/null +++ b/challenge-328/wlmb/blog.txt @@ -0,0 +1 @@ +https://wlmb.github.io/2025/07/03/PWC328/ diff --git a/challenge-328/wlmb/perl/ch-1.pl b/challenge-328/wlmb/perl/ch-1.pl new file mode 100755 index 0000000000..9cffa7b2a8 --- /dev/null +++ b/challenge-328/wlmb/perl/ch-1.pl @@ -0,0 +1,24 @@ +#!/usr/bin/env perl +# Perl weekly challenge 328 +# Task 1: Replace all ? +# +# See https://wlmb.github.io/2025/07/03/PWC328/#task-1-replace-all-? + +use v5.36; +die <<~"FIN" unless @ARGV; + Usage: $0 S1 S2... + to replace ? by lowercase letters in the lowercase strings S1 S2... + so that no letter repeats. + FIN +for(@ARGV){ + say "Expected only lowercase letters and ?'s" unless /^[a-z?]+$/; + say("Expected no repeating letters in string: $_"), next if /([a-z])\1/; + my $in=$_; + 1 while s/(.?)(\?)(.?)/replace($1, $3)/e; + say "$in -> $_"; +} +sub replace($x, $z){ + my $y="a"; + ++$y while $y eq $x or $y eq $z; + "$1$y$3" +} diff --git a/challenge-328/wlmb/perl/ch-2.pl b/challenge-328/wlmb/perl/ch-2.pl new file mode 100755 index 0000000000..3c1bb357c5 --- /dev/null +++ b/challenge-328/wlmb/perl/ch-2.pl @@ -0,0 +1,17 @@ +#!/usr/bin/env perl +# Perl weekly challenge 328 +# Task 2: Good String +# +# See https://wlmb.github.io/2025/07/03/PWC328/#task-2-good-string +use v5.36; +die <<~"FIN" unless @ARGV; + Usage: $0 S1 S2... + to convert the strings S1 S2... into good strings + without any lowercase (uppercase) letter adjacent to the corresponding + uppercase (lowercase) letter. + FIN +for(@ARGV){ + my $in=$_; + 1 while(s/([[:alpha:]])(??{my $l=lc($1); $l eq $1? uc($1):lc($1)})//); + say"$in->$_"; +} |
