in reply to Efficiently finding values of an extremity
to get the entire data set in the desired order, you could simply s/sort/minima/ to get only the minima from that set:sort { length($a) <=> length($b) or $a cmp $b } @data;
Here's how:minima { length($a) <=> length($b) or $a cmp $b } @data;
sub minima(&@) { my $comp = shift; @_ <= 1 and return(@_); my @cur = ( $_[0] ); for my $i ( 1 .. $#_ ) { local( $a, $b ) = ( $cur[0], $_[$i] ); my $r = &$comp; if ( $r > 0 ) { @cur = ($_[$i]); } elsif ( $r == 0 ) { push @cur, $_[$i]; } # else keep current best. } @cur }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Efficiently finding values of an extremity (WTDI)
by tye (Sage) on Jul 20, 2005 at 19:29 UTC | |
by jdporter (Paladin) on Jul 20, 2005 at 20:32 UTC |