aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-191/wlmb/blog.txt1
-rwxr-xr-xchallenge-191/wlmb/perl/ch-1.pl16
-rwxr-xr-xchallenge-191/wlmb/perl/ch-2.pl26
3 files changed, 43 insertions, 0 deletions
diff --git a/challenge-191/wlmb/blog.txt b/challenge-191/wlmb/blog.txt
new file mode 100644
index 0000000000..ecb82729d7
--- /dev/null
+++ b/challenge-191/wlmb/blog.txt
@@ -0,0 +1 @@
+https://wlmb.github.io/2022/11/14/PWC191/
diff --git a/challenge-191/wlmb/perl/ch-1.pl b/challenge-191/wlmb/perl/ch-1.pl
new file mode 100755
index 0000000000..e2167c6146
--- /dev/null
+++ b/challenge-191/wlmb/perl/ch-1.pl
@@ -0,0 +1,16 @@
+#!/usr/bin/env perl
+# Perl weekly challenge 191
+# Task 1: Twice Largest
+#
+# See https://wlmb.github.io/2022/11/15/PWC191/#task-1-twice-largest
+use v5.36;
+use List::Util qw(all);
+use Scalar::Util qw(looks_like_number);
+die <<"EOF" unless @ARGV;
+Usage: $0 N1 [N2...]
+to test if the largest among Ni is at least as large as twice
+any of the others.
+EOF
+die "Only numbers allowed" unless all {looks_like_number($_)} @ARGV;
+my @x=sort{$b <=> $a} @ARGV;
+say "@ARGV -> ", $x[0] >= 2*$x[1]?1:-1
diff --git a/challenge-191/wlmb/perl/ch-2.pl b/challenge-191/wlmb/perl/ch-2.pl
new file mode 100755
index 0000000000..613914ccf4
--- /dev/null
+++ b/challenge-191/wlmb/perl/ch-2.pl
@@ -0,0 +1,26 @@
+#!/usr/bin/env perl
+# Perl weekly challenge 191
+# Task 2: Cute List
+#
+# See https://wlmb.github.io/2022/11/15/PWC191/#task-2-cute-list
+use v5.36;
+use Algorithm::Combinatorics qw(permutations);
+use List::Util qw(all);
+
+sub cute($o){ # check @$o is a cute sequence
+ my @o=@$o;
+ return all {$o[$_-1]%$_==0||$_%$o[$_-1]==0} 1..@o;
+}
+
+die << "EOF" unless @ARGV;
+Usage: $0 N1 [N2...]
+to count the cute orderings of 1..Ni
+EOF
+die "Only numbers in the range 1..15 are allowed" unless all {1<=$_<=15} @ARGV;
+for(@ARGV){
+ my $iter=permutations[1..$_];
+ my $count=0;
+ my $o;
+ cute($o) && ++$count while $o=$iter->next;
+ say "$_ -> $count";
+}