aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-03-11 11:03:59 +0000
committerGitHub <noreply@github.com>2024-03-11 11:03:59 +0000
commitfbe04a4d671b187a73e39762c40a00441c390195 (patch)
treec79831e313fe4202db10af2476f1d51b9406f182
parent26f13de2848a395e08af2881ad5e0dd679a37578 (diff)
parent05bb1285b727b6b8a46b41e6c5858d54779729c9 (diff)
downloadperlweeklychallenge-club-fbe04a4d671b187a73e39762c40a00441c390195.tar.gz
perlweeklychallenge-club-fbe04a4d671b187a73e39762c40a00441c390195.tar.bz2
perlweeklychallenge-club-fbe04a4d671b187a73e39762c40a00441c390195.zip
Merge pull request #9727 from wlmb/challenges
Solve PWC260
-rw-r--r--challenge-260/wlmb/blog.txt1
-rwxr-xr-xchallenge-260/wlmb/perl/ch-1.pl16
-rwxr-xr-xchallenge-260/wlmb/perl/ch-2.pl20
3 files changed, 37 insertions, 0 deletions
diff --git a/challenge-260/wlmb/blog.txt b/challenge-260/wlmb/blog.txt
new file mode 100644
index 0000000000..811d5def4a
--- /dev/null
+++ b/challenge-260/wlmb/blog.txt
@@ -0,0 +1 @@
+https://wlmb.github.io/2024/03/10/PWC260/
diff --git a/challenge-260/wlmb/perl/ch-1.pl b/challenge-260/wlmb/perl/ch-1.pl
new file mode 100755
index 0000000000..135a9b04d9
--- /dev/null
+++ b/challenge-260/wlmb/perl/ch-1.pl
@@ -0,0 +1,16 @@
+#!/usr/bin/env perl
+# Perl weekly challenge 260
+# Task 1: Unique Occurrences
+#
+# See https://wlmb.github.io/2024/03/10/PWC260/#task-1-unique-occurrences
+use v5.36;
+use List::Util qw(uniq);
+die <<~"FIN" unless @ARGV;
+ Usage: $0 N1 [N2...]
+ to test if the number of ocurrences of each number is unique.
+ FIN
+my %counts;
+++$counts{$_} for @ARGV;
+my @counts=values %counts;
+my $result=@counts==(uniq @counts)||0;
+say "@ARGV => $result";
diff --git a/challenge-260/wlmb/perl/ch-2.pl b/challenge-260/wlmb/perl/ch-2.pl
new file mode 100755
index 0000000000..c7f9ba1ecc
--- /dev/null
+++ b/challenge-260/wlmb/perl/ch-2.pl
@@ -0,0 +1,20 @@
+#!/usr/bin/env perl
+# Perl weekly challenge 260
+# Task 2: Dictionary Rank
+#
+# See https://wlmb.github.io/2024/03/10/PWC260/#task-2-dictionary-rank
+use v5.36;
+use Algorithm::Combinatorics qw(permutations);
+use List::AllUtils qw(uniq onlyidx);
+die <<~"FIN" unless @ARGV;
+ Usage: $0 W1 [W2...]
+ to find the dictionary rank of words W1 W2...
+ FIN
+for(@ARGV){
+ my @letters=split "", my $word=lc;
+ say "$_ => ", 1+onlyidx {$_ eq $word}
+ sort{$a cmp $b}
+ uniq
+ map {join "", @$_}
+ permutations(\@letters);
+}