in reply to Permutation algorithm?

Hope this helps. But: 1) I'm a CS/Math Major, but I don't speak perl (yet). 2) I only spent like 10 minuts on this. 3) I havn't even tried to compile this. Summary) Here's a nice non-recursive algorithm, but I won't vouch for the code. ;) It should take the @ControlMatrix and produce a 3 dimensional array @perms that looks something like this:
@ControlMatrix = ( [1, 2, 0, 2], [0, 0, 2, 1] ) @perms = ( ([1, 0, 0, 0], [1, 1, 0, 0], [1, 0, 0, 1], [1, 1, 0, 1]) ([0, 0, 0, 1], [1, 1, 1, 1]) )
Here's my guess:
$index = 0; $pcount = 1; for ($names = 0; $names < @ControlNames.length; $names++) { for ($fields = 0; $fields < $ControlMatrix[$names].length; $fields++ +) { if (@ControlMatrix[$names][$fields] < 2 ) { for ($q = 0; $q < $pcount; $q++) { @perms[$names][$q][$fields] = @ControlMatrix[$names][$fields]; } } else { for ($q = 0; $q < $pcount; $q++) { @perms[$names][$q+$pcount] = @perms[names][$q]; $perms[$names][$q][$fields] = 0; $perms[$names][$q+$pcount][$fields] = 1; } $pcount *= 2; } } }