in reply to find combinations

Quick, untested Algorithm::Loops hack, but it doesn't require a huge list of nested arrays to be stored before you sort through them looking for the ones to keep:

use Algorithm::Loops qw( NestedLoops ); sub GenLances { my( $hvMechs, $members, $maxWeight )= @_; my @mechs= keys %$hvMechs; my $iter= NestedLoops( [ [0..$#mechs], (sub{[$_+1..$#mechs]})x($members-1) ], { OnlyWhen => sub { return if @_ != $members; $weight= 0; $weight += $_->{weight} for @$hvMechs{@mechs[@_]}; return $weight <= $maxWeight; }, } ); return sub { my @idx= $iter->(); return @mechs[ @idx ]; }; } # ... my $iter= GenLances( \%mechs, 3, 150 ); my @lance; while( @lance= $iter->() ) { # ... }

- tye