diff options
| author | Dave Jacoby <jacoby.david@gmail.com> | 2025-06-30 19:13:41 -0400 |
|---|---|---|
| committer | Dave Jacoby <jacoby.david@gmail.com> | 2025-06-30 19:13:41 -0400 |
| commit | 7a50c5cbcae55c5004f163af29f0afcb895f622d (patch) | |
| tree | e8e50cbd170594494de584c01b6a4e7d84e67243 | |
| parent | 7daf92e1dd4a2726fc578e87b6364ba4db3d5ad9 (diff) | |
| download | perlweeklychallenge-club-7a50c5cbcae55c5004f163af29f0afcb895f622d.tar.gz perlweeklychallenge-club-7a50c5cbcae55c5004f163af29f0afcb895f622d.tar.bz2 perlweeklychallenge-club-7a50c5cbcae55c5004f163af29f0afcb895f622d.zip | |
DAJ 328 blogged
| -rw-r--r-- | challenge-328/dave-jacoby/blog.txt | 1 | ||||
| -rw-r--r-- | challenge-328/dave-jacoby/perl/ch-1.pl | 36 | ||||
| -rw-r--r-- | challenge-328/dave-jacoby/perl/ch-2.pl | 44 |
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; } |
