On 4/4/09 Sat Apr 4, 2009 8:34 PM, "Andrew Fithian" <afit...@gmail.com> scribbled:
> What's a slick way to enumerate all subarrays of length n from a master > array of length m? For example I've been enumerating all possible two > card hands from a deck of 52 cards (n=2, m<=52) using nested for loops: > for ( $i = 0 ; $i < $#deck ; $i++ ) { > for ( $j = $i+1 ; $j <= $#deck ; $j++ ) { > someMethod( $deck[$i] , $deck[$j] ) > } > } > How do I clean this up and generalize it to larger hands (longer > subarrays). You might want to look at Math::Combinatorics, available from CPAN. A search on "combination" at search.cpan.org also reveals, Math::GSL::Combination, which appears to be a front-end to the GNU Scientific Llibrary. I haven't used either one of these, so can't recommend them, but they seem to do what you want. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/