aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuis Mochan <mochan@fis.unam.mx>2024-07-08 10:35:01 -0600
committerLuis Mochan <mochan@fis.unam.mx>2024-07-08 10:35:01 -0600
commitffb03241dde4b47c217da175444755b42caaf2d0 (patch)
tree1f5c7e60d56240fd9ad13a0b5c39db92076b3e7b
parentba07c336d3a75ece24d84048612520d232b48132 (diff)
downloadperlweeklychallenge-club-ffb03241dde4b47c217da175444755b42caaf2d0.tar.gz
perlweeklychallenge-club-ffb03241dde4b47c217da175444755b42caaf2d0.tar.bz2
perlweeklychallenge-club-ffb03241dde4b47c217da175444755b42caaf2d0.zip
Solve PWC277
-rw-r--r--challenge-277/wlmb/blog.txt1
-rwxr-xr-xchallenge-277/wlmb/perl/ch-1.pl23
-rwxr-xr-xchallenge-277/wlmb/perl/ch-2.pl14
3 files changed, 38 insertions, 0 deletions
diff --git a/challenge-277/wlmb/blog.txt b/challenge-277/wlmb/blog.txt
new file mode 100644
index 0000000000..76a3de6684
--- /dev/null
+++ b/challenge-277/wlmb/blog.txt
@@ -0,0 +1 @@
+https://wlmb.github.io/2024/07/08/PWC277/
diff --git a/challenge-277/wlmb/perl/ch-1.pl b/challenge-277/wlmb/perl/ch-1.pl
new file mode 100755
index 0000000000..0adc8da053
--- /dev/null
+++ b/challenge-277/wlmb/perl/ch-1.pl
@@ -0,0 +1,23 @@
+#!/usr/bin/env perl
+# Perl weekly challenge 277
+# Task 1: Count Common
+#
+# See https://wlmb.github.io/2024/07/08/PWC277/#task-1-count-common
+use v5.36;
+use experimental qw(for_list);
+die <<~"FIN" unless @ARGV and @ARGV%2==0;
+ Usage: $0 S11 S12 [S21 S22...]
+ to count pair of words that appear once in the space separated
+ strings Sn1 and Sn2.
+ FIN
+for my ($s1, $s2)(@ARGV){
+ my @strings=($s1, $s2);
+ my @counts;
+ my $i=0;
+ for(@strings){
+ $counts[$i]{lc $_}++ for split " ", $_;
+ $i++;
+ }
+ say((map{"words$_ = [$strings[$_]] "}(0,1)), " -> ",
+ 0+grep{$counts[0]{$_}==$counts[1]{$_}==1}keys %{$counts[0]});
+}
diff --git a/challenge-277/wlmb/perl/ch-2.pl b/challenge-277/wlmb/perl/ch-2.pl
new file mode 100755
index 0000000000..1a85627554
--- /dev/null
+++ b/challenge-277/wlmb/perl/ch-2.pl
@@ -0,0 +1,14 @@
+#!/usr/bin/env perl
+# Perl weekly challenge 277
+# Task 2: Strong Pair
+#
+# See https://wlmb.github.io/2024/07/08/PWC277/#task-2-strong-pair
+use v5.36;
+use Algorithm::Combinatorics qw(combinations);
+use List::Util qw(min uniqnum);
+die <<~"FIN" unless @ARGV;
+ Usage: $0 N1 N2...
+ to count the number of strong pairs of numbers N1 N2...
+ FIN
+my @uniq=uniqnum(@ARGV);
+say "@ARGV -> ", 0+grep {0<abs($_->[1]-$_->[0])<min(@$_)}combinations(\@uniq,2);