diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-10-12 12:12:12 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-10-12 12:12:12 +0100 |
| commit | 9f84860dbb0f87b477f8249f71c52828aeb4bd95 (patch) | |
| tree | 166d0e399ffcc19502732dbe8eb5bee08614615b | |
| parent | 047ae4c3dc542ca42ebc914fd35d2a5a80f97fec (diff) | |
| parent | cbd4d3b4d0bde27ec7b4e5cc1db8911c9941dc3e (diff) | |
| download | perlweeklychallenge-club-9f84860dbb0f87b477f8249f71c52828aeb4bd95.tar.gz perlweeklychallenge-club-9f84860dbb0f87b477f8249f71c52828aeb4bd95.tar.bz2 perlweeklychallenge-club-9f84860dbb0f87b477f8249f71c52828aeb4bd95.zip | |
Merge pull request #5013 from wlmb/challenges
Add solution to PWC134
| -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;" |
