aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Russell <adamcrussell@outlook.com>2025-07-06 17:40:10 -0400
committerAdam Russell <adamcrussell@outlook.com>2025-07-06 17:40:10 -0400
commit688341b2e99676d72fb2754bdc25733f086aa38a (patch)
treeb8aad252f32f16aa328a7700db2cde7566135989
parent0051e231d1cd185a67e698c8be88fed0fe1f0b0c (diff)
downloadperlweeklychallenge-club-688341b2e99676d72fb2754bdc25733f086aa38a.tar.gz
perlweeklychallenge-club-688341b2e99676d72fb2754bdc25733f086aa38a.tar.bz2
perlweeklychallenge-club-688341b2e99676d72fb2754bdc25733f086aa38a.zip
initial commit
-rw-r--r--challenge-328/adam-russell/blog.txt1
-rw-r--r--challenge-328/adam-russell/perl/ch-1.pl40
-rw-r--r--challenge-328/adam-russell/perl/ch-2.pl36
3 files changed, 77 insertions, 0 deletions
diff --git a/challenge-328/adam-russell/blog.txt b/challenge-328/adam-russell/blog.txt
new file mode 100644
index 0000000000..de5ea1b799
--- /dev/null
+++ b/challenge-328/adam-russell/blog.txt
@@ -0,0 +1 @@
+http://www.rabbitfarm.com/cgi-bin/blosxom/perl/2025/07/06
diff --git a/challenge-328/adam-russell/perl/ch-1.pl b/challenge-328/adam-russell/perl/ch-1.pl
new file mode 100644
index 0000000000..f0724d601e
--- /dev/null
+++ b/challenge-328/adam-russell/perl/ch-1.pl
@@ -0,0 +1,40 @@
+
+ use v5.40;
+
+ sub replace_all{
+ my($s) = @_;
+ my @s = split //, $s;
+ my @r = ();
+ {
+ my $c = shift @s;
+ my $before = pop @r;
+ my $after = shift @s;
+ my $replace;
+ if($c eq q/?/){
+
+ do{
+ $replace = chr(int(97 + rand(123 - 97)));
+ $replace = undef if $before && $replace eq $before;
+ $replace = undef if $after && $replace eq $after;
+ } while(!$replace);
+
+ push @r, $before, $replace if $before;
+ push @r, $replace if !$before;
+ }
+ else{
+ push @r, $before, $c if $before;
+ push @r, $c if !$before;
+ }
+ unshift @s, $after if $after;
+ redo if $after;
+ }
+ return join q//, @r;
+ }
+
+
+MAIN:{
+ say replace_all q/a?z/;
+ say replace_all q/pe?k/;
+ say replace_all q/gra?te/;
+}
+
diff --git a/challenge-328/adam-russell/perl/ch-2.pl b/challenge-328/adam-russell/perl/ch-2.pl
new file mode 100644
index 0000000000..68e07efd5d
--- /dev/null
+++ b/challenge-328/adam-russell/perl/ch-2.pl
@@ -0,0 +1,36 @@
+
+ use v5.40;
+
+ sub bad_pair{
+ my($s) = @_;
+ my @s = split q//, $s;
+ return undef if !@s;
+ {
+ my($x, $y) = (ord shift @s, ord shift @s);
+ if($x == $y + 32 || $x == $y - 32){
+ return chr($x) . chr($y);
+ }
+ unshift @s, chr($y);
+ redo unless @s == 1;
+ }
+ return undef;
+ }
+
+
+ sub make_good{
+ my($s) = @_;
+ {
+ my $bad_pair = bad_pair $s;
+ $s =~ s/$bad_pair// if $bad_pair;
+ redo if bad_pair $s;
+ }
+ return $s;
+ }
+
+
+MAIN:{
+ say make_good q/WeEeekly/;
+ say make_good q/abBAdD/;
+ say make_good q/abc/;
+}
+