aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-06-24 22:34:11 +0100
committerGitHub <noreply@github.com>2024-06-24 22:34:11 +0100
commit4b157dc2dab7a337e488dfb8f388c217ceff6292 (patch)
tree1b6054c276a9a0a6aad25adf0b9e9531ce14f8e4
parent0b31691a71d7f2193e7f3b7c04632486720094cd (diff)
parentefe32f2dc69c3d8bd4c96d07cda0e0a582acf83b (diff)
downloadperlweeklychallenge-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.txt1
-rwxr-xr-xchallenge-275/wlmb/perl/ch-1.pl13
-rwxr-xr-xchallenge-275/wlmb/perl/ch-2.pl23
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);
+}