From 282303002673fb67ec499f67c90be22a8d509f5f Mon Sep 17 00:00:00 2001 From: Jörg Sommrey <28217714+jo-37@users.noreply.github.com> Date: Sat, 23 Jan 2021 15:47:47 +0100 Subject: Simplify min_ind --- challenge-096/jo-37/perl/ch-2.pl | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/challenge-096/jo-37/perl/ch-2.pl b/challenge-096/jo-37/perl/ch-2.pl index 72f1a6afb9..cdb9eaa346 100755 --- a/challenge-096/jo-37/perl/ch-2.pl +++ b/challenge-096/jo-37/perl/ch-2.pl @@ -140,18 +140,10 @@ sub cost ($repl) { } # Find the minimum in an N-dim piddle together with the corresponding -# index. Though this looks complicated, it is very efficient. -sub min_ind ($min) { - my (@index, $index); - - # Reduce dimension by projection via minimum down to zero (getting - # to the global minimum as a scalar) and record the index piddle for - # each dimension. - ($min, undef, $index[@index]) = $min->minmaximum while $min->dims; - - # Expand the target index bottom-up from the record by successively - # applying the so far built index to the next higher dimension index. - $index = $_->indexND($index)->glue(0, $index) for reverse @index; +# index. +sub min_ind ($pdl) { + my $min = min $pdl; + my $index = whichND($pdl == $min)->slice(',(0)'); ($min, $index); } -- cgit