aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuis Mochan <mochan@fis.unam.mx>2025-09-15 13:42:45 -0600
committerLuis Mochan <mochan@fis.unam.mx>2025-09-15 13:42:45 -0600
commit5e9b9caf403ffb066d900d120dcaf409dc1c4e7a (patch)
treebbc6b658816f78ae016f3b0ef5a1471a5ea27d7a
parent0d08beea92cbe83cdce61a6f56ea40638af6c5b1 (diff)
downloadperlweeklychallenge-club-5e9b9caf403ffb066d900d120dcaf409dc1c4e7a.tar.gz
perlweeklychallenge-club-5e9b9caf403ffb066d900d120dcaf409dc1c4e7a.tar.bz2
perlweeklychallenge-club-5e9b9caf403ffb066d900d120dcaf409dc1c4e7a.zip
Error checking
-rwxr-xr-xchallenge-339/wlmb/perl/ch-1.pl21
-rwxr-xr-xchallenge-339/wlmb/perl/ch-2.pl4
2 files changed, 13 insertions, 12 deletions
diff --git a/challenge-339/wlmb/perl/ch-1.pl b/challenge-339/wlmb/perl/ch-1.pl
index 4a51a15470..77066bffd6 100755
--- a/challenge-339/wlmb/perl/ch-1.pl
+++ b/challenge-339/wlmb/perl/ch-1.pl
@@ -15,17 +15,18 @@ die <<~"FIN" unless @ARGV;
FIN
for(@ARGV){
try {
- my $in=pdl($_);
- my $products=$in*$in(*1);
- my $diffs=$products-$products(*1,*1); # Xi*Xj-Xk*Xl
- my ($i, $j, $k, $l) = $diffs->ndcoords->mv(0,-1)->dog; #coordinates into ndarray $diffs
- $diffs=$diffs->where(
- ($i!=$j)&($i!=$k)&($i!=$l)
- &($j!=$k)&($j!=$l)
- &($k!=$l)); # select elements with no repeating coordinates
- say "$_ -> ", $diffs->max;
+ my $in=pdl($_);
+ die "Expected four or more numbers" unless $in->dim(0)>=4;
+ my $products=$in*$in(*1);
+ my $diffs=$products-$products(*1,*1); # Xi*Xj-Xk*Xl
+ my ($i, $j, $k, $l) = $diffs->ndcoords->mv(0,-1)->dog; #coordinates into ndarray $diffs
+ $diffs=$diffs->where(
+ ($i!=$j)&($i!=$k)&($i!=$l)
+ &($j!=$k)&($j!=$l)
+ &($k!=$l)); # select elements with no repeating coordinates
+ say "$_ -> ", $diffs->max;
}
catch($e){
- warn $e;
+ warn $e;
}
}
diff --git a/challenge-339/wlmb/perl/ch-2.pl b/challenge-339/wlmb/perl/ch-2.pl
index 9a81fa78a3..e642cfe3c3 100755
--- a/challenge-339/wlmb/perl/ch-2.pl
+++ b/challenge-339/wlmb/perl/ch-2.pl
@@ -14,9 +14,9 @@ die <<~"FIN" unless @ARGV;
FIN
for(@ARGV){
try{
- say "$_ -> ", append(0,pdl($_))->cumusumover->max
+ say "$_ -> ", append(0,pdl($_))->cumusumover->max
}
catch($e){
- warn $e;
+ warn $e;
}
}