aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuis Mochan <mochan@fis.unam.mx>2024-09-08 21:28:54 -0600
committerLuis Mochan <mochan@fis.unam.mx>2024-09-08 21:28:54 -0600
commit9cd8d5744483532cef7030180b829b07b4a97c5d (patch)
tree4ca8ff64353888794ddf3c776fdc251ecd8fb03a
parent3c67a5382758155040d6598a2fa01ca5fd6d25d9 (diff)
downloadperlweeklychallenge-club-9cd8d5744483532cef7030180b829b07b4a97c5d.tar.gz
perlweeklychallenge-club-9cd8d5744483532cef7030180b829b07b4a97c5d.tar.bz2
perlweeklychallenge-club-9cd8d5744483532cef7030180b829b07b4a97c5d.zip
Solve PWC286
-rw-r--r--challenge-286/wlmb/blog.txt1
-rwxr-xr-xchallenge-286/wlmb/perl/ch-1.pl8
-rwxr-xr-xchallenge-286/wlmb/perl/ch-2.pl22
3 files changed, 31 insertions, 0 deletions
diff --git a/challenge-286/wlmb/blog.txt b/challenge-286/wlmb/blog.txt
new file mode 100644
index 0000000000..16cf556b09
--- /dev/null
+++ b/challenge-286/wlmb/blog.txt
@@ -0,0 +1 @@
+https://wlmb.github.io/2024/09/08/PWC286/
diff --git a/challenge-286/wlmb/perl/ch-1.pl b/challenge-286/wlmb/perl/ch-1.pl
new file mode 100755
index 0000000000..7ae442676f
--- /dev/null
+++ b/challenge-286/wlmb/perl/ch-1.pl
@@ -0,0 +1,8 @@
+#!/usr/bin/env perl
+# Perl weekly challenge 286
+# Task 1: Self Spammer
+#
+# See https://wlmb.github.io/2024/09/08/PWC286/#task-1-self-spammer
+use v5.36;
+my @words = qw( @words = qw( ) say $words [ rand( 0+@words ) ] ; );
+say $words [ rand( 0+@words ) ] ;
diff --git a/challenge-286/wlmb/perl/ch-2.pl b/challenge-286/wlmb/perl/ch-2.pl
new file mode 100755
index 0000000000..08163d0a8a
--- /dev/null
+++ b/challenge-286/wlmb/perl/ch-2.pl
@@ -0,0 +1,22 @@
+#!/usr/bin/env perl
+# Perl weekly challenge 286
+# Task 2: Order Game
+#
+# See https://wlmb.github.io/2024/09/08/PWC286/#task-2-order-game
+use v5.36;
+use List::Util qw(min max);
+use experimental qw(for_list);
+die <<~"FIN" unless @ARGV and ((@ARGV&(@ARGV-1))==0); #finite power of 2
+ Usage: $0 N1 N2...Nm
+ where m is a power of two to choose min max of consecutive pairs
+ and iterate until surviving element is found
+ FIN
+my @next=@ARGV;
+while(@next>2){
+ my @minmax;
+ for my($p,$q,$r,$s)(@next){
+ push @minmax, min($p,$q),max($r,$s);
+ }
+ @next=@minmax;
+}
+say "@ARGV -> ",min(@next)