diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-04-23 16:44:41 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-23 16:44:41 +0100 |
| commit | 463b8069e4de65191931208db57ff43bf4a00700 (patch) | |
| tree | 04ee1d529a586fefa37097fc2643a10d94b208bf | |
| parent | 45ab012ce403904252616a7237dc1d451c7064de (diff) | |
| parent | c74daf4c04b5dd008a464b9ec05d3a836a512623 (diff) | |
| download | perlweeklychallenge-club-463b8069e4de65191931208db57ff43bf4a00700.tar.gz perlweeklychallenge-club-463b8069e4de65191931208db57ff43bf4a00700.tar.bz2 perlweeklychallenge-club-463b8069e4de65191931208db57ff43bf4a00700.zip | |
Merge pull request #9976 from wlmb/challenges
Solve PWC266
| -rw-r--r-- | challenge-266/wlmb/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-266/wlmb/perl/ch-1.pl | 15 | ||||
| -rwxr-xr-x | challenge-266/wlmb/perl/ch-2.pl | 20 |
3 files changed, 36 insertions, 0 deletions
diff --git a/challenge-266/wlmb/blog.txt b/challenge-266/wlmb/blog.txt new file mode 100644 index 0000000000..1c61a67b9e --- /dev/null +++ b/challenge-266/wlmb/blog.txt @@ -0,0 +1 @@ +https://wlmb.github.io/2024/04/21/PWC266/ diff --git a/challenge-266/wlmb/perl/ch-1.pl b/challenge-266/wlmb/perl/ch-1.pl new file mode 100755 index 0000000000..d86d47628d --- /dev/null +++ b/challenge-266/wlmb/perl/ch-1.pl @@ -0,0 +1,15 @@ +#!/usr/bin/env perl +# Perl weekly challenge 266 +# Task 1: Uncommon Words +# +# See https://wlmb.github.io/2024/04/21/PWC266/#task-1-uncommon-words +use v5.36; +die <<~"FIN" unless @ARGV; + Usage: $0 S1 [S2...] + to find uncommon words in the strings S1, S2... + FIN +my %count; +$count{lc $_}++ for split /\W+/, "@ARGV"; +my @output=sort {$a cmp $b} grep {$count{$_}==1} keys %count; +push @output, "''" unless @output; +say join " ", map({"'".$_."'"} @ARGV), "->", @output; diff --git a/challenge-266/wlmb/perl/ch-2.pl b/challenge-266/wlmb/perl/ch-2.pl new file mode 100755 index 0000000000..7542b40e49 --- /dev/null +++ b/challenge-266/wlmb/perl/ch-2.pl @@ -0,0 +1,20 @@ +#!/usr/bin/env perl +# Perl weekly challenge 266 +# Task 2: X Matrix +# +# See https://wlmb.github.io/2024/04/21/PWC266/#task-2-x-matrix +use v5.36; +use PDL; +use PDL::NiceSlice; +die <<~"FIN" unless @ARGV; + Usage: $0 M1 [M2...] + to find out if the matrices M1, M2... are X shaped. + Each matrix should be of the form "[[M11 M12...][M21 M22...]...]" + where Mij are the matrix elements. Separating commas are optional. + FIN +for(@ARGV){ + my $matrix=pdl $_; + my $x=($matrix->xvals==$matrix->yvals) | ($matrix->xvals->(-1:0)==$matrix->yvals); + my $output=(!!$matrix == $x)->all?"True":"False"; + say "$matrix -> $output"; +} |
