aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuis Mochan <mochan@fis.unam.mx>2021-10-11 22:43:39 -0500
committerLuis Mochan <mochan@fis.unam.mx>2021-10-11 22:43:39 -0500
commitcbd4d3b4d0bde27ec7b4e5cc1db8911c9941dc3e (patch)
treeca6606703c47811e398306173d4ce20586633e25
parentd1cc085e5d97d49b827aad79bd57a909caa4b0a1 (diff)
downloadperlweeklychallenge-club-cbd4d3b4d0bde27ec7b4e5cc1db8911c9941dc3e.tar.gz
perlweeklychallenge-club-cbd4d3b4d0bde27ec7b4e5cc1db8911c9941dc3e.tar.bz2
perlweeklychallenge-club-cbd4d3b4d0bde27ec7b4e5cc1db8911c9941dc3e.zip
Add solution to PWC134
-rw-r--r--challenge-134/wlmb/blog.txt1
-rwxr-xr-xchallenge-134/wlmb/perl/ch-1.pl21
-rwxr-xr-xchallenge-134/wlmb/perl/ch-2.pl17
3 files changed, 39 insertions, 0 deletions
diff --git a/challenge-134/wlmb/blog.txt b/challenge-134/wlmb/blog.txt
new file mode 100644
index 0000000000..ed280f4d10
--- /dev/null
+++ b/challenge-134/wlmb/blog.txt
@@ -0,0 +1 @@
+https://wlmb.github.io/2021/10/11/PWC134/
diff --git a/challenge-134/wlmb/perl/ch-1.pl b/challenge-134/wlmb/perl/ch-1.pl
new file mode 100755
index 0000000000..9d130701f8
--- /dev/null
+++ b/challenge-134/wlmb/perl/ch-1.pl
@@ -0,0 +1,21 @@
+#!/usr/bin/env perl
+# Perl weekly challenge 134
+# Task 1: Pandigital numbers
+#
+# See https://wlmb.github.io/2021/10/11/PWC134/#task-1-pandigital-numbers
+use v5.12;
+use warnings;
+use List::Util qw(product);
+use List::Permutor;
+say "Usage: ./ch-1.pl howmany [base]" and exit unless @ARGV>0;
+my ($howmany, $base)=@ARGV;
+$base//=10; #default
+# The following only works if $howmany is smaller than ($base-1)!
+# and $base>2
+say "First $howmany pandigital numbers in base $base";
+say "I'm unable to cope with a base <= 2" and exit unless $base>=3;
+my $factorial=product(1..$base-1);
+say "I'm unable to cope with more than ", $base-1,"!=$factorial numbers in base $base"
+ and exit unless $howmany<=$factorial;
+my $p=List::Permutor->new(1,0,2..$base-1);
+say join $base>10?"-":"", $p->next for 1..$howmany;
diff --git a/challenge-134/wlmb/perl/ch-2.pl b/challenge-134/wlmb/perl/ch-2.pl
new file mode 100755
index 0000000000..9289e02aa4
--- /dev/null
+++ b/challenge-134/wlmb/perl/ch-2.pl
@@ -0,0 +1,17 @@
+#!/usr/bin/env perl
+# Perl weekly challenge 134
+# Task 2: Distinct Terms Count
+#
+# See https://wlmb.github.io/2021/10/11/PWC134/#task-2-distinct-terms-count
+use v5.12;
+use warnings;
+use PDL;
+use List::Util qw(uniqint);
+say "Usage: ./ch-2.pl N M" and exit unless @ARGV==2;
+my ($m, $n)=@ARGV;
+my $table=(zeroes($n,$m)->ndcoords+1)->prodover;
+my $uniq=$table->uniq;
+my $count=$uniq->nelem;
+say "Input: m=$m, n=$n";
+say "Output: $table"; # Could have done a better format
+say "Distinct terms: $uniq\nCount: $count;"