From 5e9b9caf403ffb066d900d120dcaf409dc1c4e7a Mon Sep 17 00:00:00 2001 From: Luis Mochan Date: Mon, 15 Sep 2025 13:42:45 -0600 Subject: Error checking --- challenge-339/wlmb/perl/ch-1.pl | 21 +++++++++++---------- challenge-339/wlmb/perl/ch-2.pl | 4 ++-- 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; } } -- cgit