diff options
| -rw-r--r-- | challenge-275/wlmb/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-275/wlmb/perl/ch-1.pl | 13 | ||||
| -rwxr-xr-x | challenge-275/wlmb/perl/ch-2.pl | 23 |
3 files changed, 37 insertions, 0 deletions
diff --git a/challenge-275/wlmb/blog.txt b/challenge-275/wlmb/blog.txt new file mode 100644 index 0000000000..ec473aa598 --- /dev/null +++ b/challenge-275/wlmb/blog.txt @@ -0,0 +1 @@ +https://wlmb.github.io/2024/06/24/PWC275/ diff --git a/challenge-275/wlmb/perl/ch-1.pl b/challenge-275/wlmb/perl/ch-1.pl new file mode 100755 index 0000000000..f4d58c34c6 --- /dev/null +++ b/challenge-275/wlmb/perl/ch-1.pl @@ -0,0 +1,13 @@ +#!/usr/bin/env perl +# Perl weekly challenge 275 +# Task 1: Broken Keys +# +# See https://wlmb.github.io/2024/06/24/PWC275/#task-1-broken-keys +use v5.36; +die <<~"FIN" unless @ARGV; + Usage: $0 "S" K1 K2... + to count how many words in the sentence S don't contain the broken keys K1 K2... + FIN +my ($sentence, @keys)=@ARGV; +my @words=split " ",$sentence; +say "sentence: \"$sentence\" keys: @keys -> ", 0+grep{!/[@keys]/i}@words; diff --git a/challenge-275/wlmb/perl/ch-2.pl b/challenge-275/wlmb/perl/ch-2.pl new file mode 100755 index 0000000000..ef95f64f5d --- /dev/null +++ b/challenge-275/wlmb/perl/ch-2.pl @@ -0,0 +1,23 @@ +#!/usr/bin/env perl +# Perl weekly challenge 275 +# Task 2: Replace Digits +# +# See https://wlmb.github.io/2024/06/24/PWC275/#task-2-replace-digits +use v5.36; +die <<~"FIN" unless @ARGV; + Usage: $0 S1 S2... + to replace digits by the previous character shifted the corresponding + number of spaces + FIN +for(@ARGV){ + my ($last, $current); + my $result=join "", map {($last, $current)=nextchar($last, $_); $current} split "", $_; + say "$_ -> $result"; +} +sub nextchar($last, $current){ + die "Digit before first char" if /[0-9]/ && not defined $last; + $current=chr(ord($last)+$current) if /[0-9]/; + $last=$current unless /[0-9]/; + die "Out of range" unless $current=~/[a-z]/i; + return ($last, $current); +} |
