diff options
| -rw-r--r-- | challenge-134/wlmb/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-134/wlmb/perl/ch-1.pl | 21 | ||||
| -rwxr-xr-x | challenge-134/wlmb/perl/ch-2.pl | 17 |
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;" |
