diff options
| -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"; +} |
