aboutsummaryrefslogtreecommitdiff
path: root/challenge-234
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2023-09-17 22:17:46 +0100
committerGitHub <noreply@github.com>2023-09-17 22:17:46 +0100
commite6fc9692dbfe401a7d5918bc91dfa2ee7bcfd213 (patch)
treeb0f0851ce302551f9f4359c1209ac17a2a81a3f8 /challenge-234
parent3f85224aa3a84d4fb99755152cba5176cf49b795 (diff)
parentc2f37f15a35dc0146cc7cbd3f13f2f5fabed02a3 (diff)
downloadperlweeklychallenge-club-e6fc9692dbfe401a7d5918bc91dfa2ee7bcfd213.tar.gz
perlweeklychallenge-club-e6fc9692dbfe401a7d5918bc91dfa2ee7bcfd213.tar.bz2
perlweeklychallenge-club-e6fc9692dbfe401a7d5918bc91dfa2ee7bcfd213.zip
Merge pull request #8685 from wlmb/challenges
solve pwc234
Diffstat (limited to 'challenge-234')
-rw-r--r--challenge-234/wlmb/blog.txt1
-rwxr-xr-xchallenge-234/wlmb/perl/ch-1.pl27
-rwxr-xr-xchallenge-234/wlmb/perl/ch-2.pl21
3 files changed, 49 insertions, 0 deletions
diff --git a/challenge-234/wlmb/blog.txt b/challenge-234/wlmb/blog.txt
new file mode 100644
index 0000000000..38fcd698e6
--- /dev/null
+++ b/challenge-234/wlmb/blog.txt
@@ -0,0 +1 @@
+https://wlmb.github.io/2023/09/11/PWC234/
diff --git a/challenge-234/wlmb/perl/ch-1.pl b/challenge-234/wlmb/perl/ch-1.pl
new file mode 100755
index 0000000000..1b38c6413b
--- /dev/null
+++ b/challenge-234/wlmb/perl/ch-1.pl
@@ -0,0 +1,27 @@
+#!/usr/bin/env perl
+# Perl weekly challenge 234
+# Task 1: Common Characters
+#
+# See https://wlmb.github.io/2023/09/11/PWC234/#task-1-common-characters
+use v5.36;
+use List::Util qw(min);
+die <<~"FIN" unless @ARGV;
+ Usage: $0 W1 [W2...]
+ to find the common characters in all words W1, W2...
+ FIN
+my @letters_of_word;
+for(@ARGV){
+ my %count_of_letter;
+ $count_of_letter{$_}++ for split "";
+ push @letters_of_word, \%count_of_letter;
+}
+my $number_of_words=@letters_of_word;
+my @result=map {
+ my $letter=$_;
+ my $repetition=min map {
+ my $word_number=$_;
+ $letters_of_word[$word_number]{$letter}//0
+ } 0..$number_of_words-1;
+ ($letter) x $repetition;
+} keys %{$letters_of_word[0]};
+say "@ARGV -> @result";
diff --git a/challenge-234/wlmb/perl/ch-2.pl b/challenge-234/wlmb/perl/ch-2.pl
new file mode 100755
index 0000000000..1926cc7bd6
--- /dev/null
+++ b/challenge-234/wlmb/perl/ch-2.pl
@@ -0,0 +1,21 @@
+#!/usr/bin/env perl
+# Perl weekly challenge 234
+# Task 2: Unequal Triplets
+#
+# See https://wlmb.github.io/2023/09/11/PWC234/#task-2-unequal-triplets
+use v5.36;
+use Algorithm::Combinatorics qw(combinations);
+use List::Util qw(sum0 product);
+die <<~"FIN" unless @ARGV;
+ Usage: $0 N1 [N2...]
+ to count the number of unequal triplets in the set {N1 N2...}
+ FIN
+my %count_for_number;
+++$count_for_number{$_} for @ARGV;
+my @numbers=keys %count_for_number;
+my $result=@numbers<3
+ ? 0
+ : sum0 map {
+ product @count_for_number{@$_}
+} combinations(\@numbers,3);
+say "@ARGV -> $result",