diff options
| author | Jörg Sommrey <28217714+jo-37@users.noreply.github.com> | 2021-01-23 15:48:37 +0100 |
|---|---|---|
| committer | Jörg Sommrey <28217714+jo-37@users.noreply.github.com> | 2021-01-23 15:48:37 +0100 |
| commit | fb4db2c5edf50a1c86bff25bb416f44ad4a7725d (patch) | |
| tree | 795fd92bdcef1eb6e538b9eee9dffe1d57ad5593 | |
| parent | f5e532c3587520e07eb63b349fae18144f3a1db5 (diff) | |
| parent | 282303002673fb67ec499f67c90be22a8d509f5f (diff) | |
| download | perlweeklychallenge-club-fb4db2c5edf50a1c86bff25bb416f44ad4a7725d.tar.gz perlweeklychallenge-club-fb4db2c5edf50a1c86bff25bb416f44ad4a7725d.tar.bz2 perlweeklychallenge-club-fb4db2c5edf50a1c86bff25bb416f44ad4a7725d.zip | |
Simplify min_ind
| -rwxr-xr-x | challenge-096/jo-37/perl/ch-2.pl | 16 |
1 files 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); } |
