aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-02-05 19:06:36 +0000
committerGitHub <noreply@github.com>2024-02-05 19:06:36 +0000
commit68b1f5cb5d9e6eca9364a7fc36d554d2e26c1ab8 (patch)
tree93213884751ae7ba969c3dfb1d52a4aa6691b799
parent9850474c2c0a453fda1a22ca8c8cd077692682b6 (diff)
parente3a92ba33f405797167d4646efb4f76c5d23ed7e (diff)
downloadperlweeklychallenge-club-68b1f5cb5d9e6eca9364a7fc36d554d2e26c1ab8.tar.gz
perlweeklychallenge-club-68b1f5cb5d9e6eca9364a7fc36d554d2e26c1ab8.tar.bz2
perlweeklychallenge-club-68b1f5cb5d9e6eca9364a7fc36d554d2e26c1ab8.zip
Merge pull request #9524 from wlmb/challenges
Solve PWC255
-rw-r--r--challenge-255/wlmb/blog.txt1
-rwxr-xr-xchallenge-255/wlmb/perl/ch-1.pl19
-rwxr-xr-xchallenge-255/wlmb/perl/ch-2.pl16
3 files changed, 36 insertions, 0 deletions
diff --git a/challenge-255/wlmb/blog.txt b/challenge-255/wlmb/blog.txt
new file mode 100644
index 0000000000..fdbdb25e89
--- /dev/null
+++ b/challenge-255/wlmb/blog.txt
@@ -0,0 +1 @@
+https://wlmb.github.io/2024/02/05/PWC255/
diff --git a/challenge-255/wlmb/perl/ch-1.pl b/challenge-255/wlmb/perl/ch-1.pl
new file mode 100755
index 0000000000..b4fd9c7739
--- /dev/null
+++ b/challenge-255/wlmb/perl/ch-1.pl
@@ -0,0 +1,19 @@
+#!/usr/bin/env perl
+# Perl weekly challenge 255
+# Task 1: Odd Character
+#
+# See https://wlmb.github.io/2024/02/05/PWC255/#task-1-odd-character
+use v5.36;
+use experimental qw(for_list);
+die <<~"FIN" unless @ARGV && @ARGV%2==0;
+ Usage: $0 S0 T0 [S1 T1...]
+ to find the odd characters in the string pairs Sn Tn
+ FIN
+for my ($s,$t)(@ARGV){
+ warn "Length should differ by one" unless length $t == 1+length $s;
+ my %count;
+ ++$count{$_} for split "", fc $s;
+ --$count{$_}||delete $count{$_} for split "", fc $t;
+ warn "More than one odd character" unless (keys %count)==1;
+ say "$t, $s -> ", keys %count;
+}
diff --git a/challenge-255/wlmb/perl/ch-2.pl b/challenge-255/wlmb/perl/ch-2.pl
new file mode 100755
index 0000000000..aabc08ca56
--- /dev/null
+++ b/challenge-255/wlmb/perl/ch-2.pl
@@ -0,0 +1,16 @@
+#!/usr/bin/env perl
+# Perl weekly challenge 255
+# Task 2: Most Frequent Word
+#
+# See https://wlmb.github.io/2024/02/05/PWC255/#task-2-most-frequent-word
+use v5.36;
+use List::UtilsBy qw(max_by);
+die <<~"FIN" unless @ARGV==2;
+ Usage: $0 S ¨P
+ to find the most frequent word in paragraph P excluding the word S
+ FIN
+my ($w, $p)=@ARGV;
+my %count;
+++$count{fc $_} for split /\W+/, $p;
+delete $count{fc $w};
+say "\n$w\n$p\n->\n", max_by{$count{$_}} keys %count;