aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2025-07-02 23:30:07 +0100
committerGitHub <noreply@github.com>2025-07-02 23:30:07 +0100
commitaf47e7f11b315d4bdb06ca2203d8857c0d2c176f (patch)
treea243a1c564b14d646c14168349836da43ff8b2d7
parent9b8a142d066824112f32998e348bf3cf72b543b8 (diff)
parent7a50c5cbcae55c5004f163af29f0afcb895f622d (diff)
downloadperlweeklychallenge-club-af47e7f11b315d4bdb06ca2203d8857c0d2c176f.tar.gz
perlweeklychallenge-club-af47e7f11b315d4bdb06ca2203d8857c0d2c176f.tar.bz2
perlweeklychallenge-club-af47e7f11b315d4bdb06ca2203d8857c0d2c176f.zip
Merge pull request #12269 from jacoby/master
DAJ 328 blogged
-rw-r--r--challenge-328/dave-jacoby/blog.txt1
-rw-r--r--challenge-328/dave-jacoby/perl/ch-1.pl36
-rw-r--r--challenge-328/dave-jacoby/perl/ch-2.pl44
3 files changed, 81 insertions, 0 deletions
diff --git a/challenge-328/dave-jacoby/blog.txt b/challenge-328/dave-jacoby/blog.txt
new file mode 100644
index 0000000000..02c3e4fdc7
--- /dev/null
+++ b/challenge-328/dave-jacoby/blog.txt
@@ -0,0 +1 @@
+https://jacoby-lpwk.onrender.com/2025/06/30/kinda-predisastered-weekly-challenge-328.html
diff --git a/challenge-328/dave-jacoby/perl/ch-1.pl b/challenge-328/dave-jacoby/perl/ch-1.pl
new file mode 100644
index 0000000000..a42a092836
--- /dev/null
+++ b/challenge-328/dave-jacoby/perl/ch-1.pl
@@ -0,0 +1,36 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use experimental qw{ say state postderef signatures };
+
+my @examples = (
+
+ qw{ a?z pe?k gra?te b?a?c?d?a }
+);
+
+for my $input (@examples) {
+ my $output = replace_all_Qs($input);
+ say <<"END";
+ Input: \@str = "$input"
+ Output: "$output"
+END
+}
+
+sub replace_all_Qs($example) {
+ my @qs =
+ grep { '?' eq substr( $example, $_, 1 ) } 0 .. -1 + length $example;
+ for my $q (@qs) {
+ for my $l ( 'A' .. 'Z' ) {
+ my $ll = $l . $l;
+ my $c = $example;
+ substr( $c, $q, 1 ) = $l;
+ if ( $c !~ /$ll/mix ) {
+ $example = $c;
+ last;
+ }
+ }
+ }
+ return $example;
+}
+
diff --git a/challenge-328/dave-jacoby/perl/ch-2.pl b/challenge-328/dave-jacoby/perl/ch-2.pl
new file mode 100644
index 0000000000..00d33d78e1
--- /dev/null
+++ b/challenge-328/dave-jacoby/perl/ch-2.pl
@@ -0,0 +1,44 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use experimental qw{ say state postderef signatures };
+
+my @examples = (
+ qw{ WeEeekly abBAdDabc }
+);
+
+for my $input (@examples) {
+ my $output = good_string($input);
+ say <<"END";
+ Input: \@str = "$input"
+ Output: "$output"
+END
+}
+
+sub good_string ($input) {
+TOP: while (1) {
+ for my $i ( 0 .. -1 + length $input ) {
+ my $c = substr $input, $i, 1;
+ if ( _is_uppercase($c) ) {
+ my $cc = lc $c;
+ if ( $cc eq substr $input, $i + 1, 1 ) {
+ substr( $input, $i + 1, 1 ) = '';
+ substr( $input, $i, 1 ) = '';
+ next TOP;
+ }
+ }
+ else {
+ my $cc = uc $c;
+ if ( $cc eq substr $input, $i + 1, 1 ) {
+ substr( $input, $i + 1, 1 ) = '';
+ substr( $input, $i, 1 ) = '';
+ next TOP;
+ }
+ }
+ }
+ last;
+ }
+ return $input;
+}
+sub _is_uppercase($char) { return $char eq uc $char ? 1 : 0; }