aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2023-02-22 23:42:26 +0000
committerGitHub <noreply@github.com>2023-02-22 23:42:26 +0000
commit7cf04f858315240abf8b4a09f2d97125ee93d161 (patch)
treed352f017bf4c3ca5d47ee58c0efef00e922e8575
parent78c8cf00255f1c5516b332950be2ea2e97f47ec5 (diff)
parent0c9421c9735b996f10d5136a4603f5010cafc4da (diff)
downloadperlweeklychallenge-club-7cf04f858315240abf8b4a09f2d97125ee93d161.tar.gz
perlweeklychallenge-club-7cf04f858315240abf8b4a09f2d97125ee93d161.tar.bz2
perlweeklychallenge-club-7cf04f858315240abf8b4a09f2d97125ee93d161.zip
Merge pull request #7604 from wlmb/master
Solve PWC205
-rw-r--r--challenge-205/wlmb/blog.txt2
-rwxr-xr-xchallenge-205/wlmb/perl/ch-1.pl14
-rwxr-xr-xchallenge-205/wlmb/perl/ch-2.pl13
3 files changed, 29 insertions, 0 deletions
diff --git a/challenge-205/wlmb/blog.txt b/challenge-205/wlmb/blog.txt
new file mode 100644
index 0000000000..3093a2ced6
--- /dev/null
+++ b/challenge-205/wlmb/blog.txt
@@ -0,0 +1,2 @@
+https://wlmb.github.io/2023/02/20/PWC205/
+
diff --git a/challenge-205/wlmb/perl/ch-1.pl b/challenge-205/wlmb/perl/ch-1.pl
new file mode 100755
index 0000000000..5ca49bfbd8
--- /dev/null
+++ b/challenge-205/wlmb/perl/ch-1.pl
@@ -0,0 +1,14 @@
+#!/usr/bin/env perl
+# Perl weekly challenge 205
+# Task 1: Third Highest
+#
+# See https://wlmb.github.io/2023/02/20/PWC205/#task-1-third-highest
+use v5.36;
+use List::Util qw(uniqint);
+die <<~"FIN" unless @ARGV;
+ Usage: $0 N1 [N2...]
+ to find the third highest number from the list N1 N2...
+ FIN
+my @list=(sort {$b<=>$a} uniqint @ARGV); # filter out repetitions and sort descending
+push @list, ($list[0]) x 2; # Add two copies of the maximum at the end of the list
+say join " ", @ARGV, "->", $list[2];
diff --git a/challenge-205/wlmb/perl/ch-2.pl b/challenge-205/wlmb/perl/ch-2.pl
new file mode 100755
index 0000000000..58665e6e2e
--- /dev/null
+++ b/challenge-205/wlmb/perl/ch-2.pl
@@ -0,0 +1,13 @@
+#!/usr/bin/env perl
+# Perl weekly challenge 205
+# Task 2: Maximum XOR
+#
+# See https://wlmb.github.io/2023/02/20/PWC205/#task-2-maximum-xor
+use v5.36;
+use Algorithm::Combinatorics qw(combinations);
+use List::Util qw(max);
+die <<~"FIN" unless @ARGV >= 2;
+ Usage: $0 N1 N2 [N3...]
+ to find the maximum xor of pairs from the list N1 N2 N3...
+ FIN
+say join " ", @ARGV, "->", max map {$_->[0] ^ $_->[1]} combinations([@ARGV],2);