in reply to Challenge: Generate fixed size combination across groups without duplicates

Is this a solution? Update: To answer my own question. No. It produces duplicates! :(

#! perl -slw use strict; use Data::Dump qw[ pp ]; use Algorithm::Combinatorics qw[ variations ]; sub nFor(&@) { my $code = shift; die "First argument must be a code ref" unless ref( $code ) eq 'CO +DE'; my @limits = @_; my @indices = ( 0 ) x @limits; for( my $i = $#limits; $i >= 0; ) { $i = $#limits; $code->( @indices ), ++$indices[ $i ] while $indices[ $i ] < $limits[ $i ]; $i = $#limits; $indices[ $i ] = 0, ++$indices[ --$i ] while $i >= 0 and $indices[ $i ] == $limits[ $i ]; } } my @g = ( [ qw[ A B C ] ], [ qw[ 1 2 3 4 ] ], [ qw[ yellow blue green ] ], [ qw[ tiny small medium large gigantic ] ], ); my $fSize = 2; my @varies = variations( [ 0 .. $#g ], $fSize ); nFor { for my $v ( @varies ) { print join ' ', map{ $g[ $_ ][ $_[ $_ ] ] } @$v } } map scalar @$_, @g;

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
  • Comment on Re: Challenge: Generate fixed size combination across groups without duplicates
  • Download Code