diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-06-24 22:34:11 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-24 22:34:11 +0100 |
| commit | 4b157dc2dab7a337e488dfb8f388c217ceff6292 (patch) | |
| tree | 1b6054c276a9a0a6aad25adf0b9e9531ce14f8e4 | |
| parent | 0b31691a71d7f2193e7f3b7c04632486720094cd (diff) | |
| parent | efe32f2dc69c3d8bd4c96d07cda0e0a582acf83b (diff) | |
| download | perlweeklychallenge-club-4b157dc2dab7a337e488dfb8f388c217ceff6292.tar.gz perlweeklychallenge-club-4b157dc2dab7a337e488dfb8f388c217ceff6292.tar.bz2 perlweeklychallenge-club-4b157dc2dab7a337e488dfb8f388c217ceff6292.zip | |
Merge pull request #10321 from wlmb/challenges
Solve PWC275
| -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); +} |
