Alright gurus, here's something that's been stumping me. I've got the following arrays:
my @ControlMatrix = ( [ 1, 2, 1, 0, 0, 1, 2, 1, 1, 2, 1 ], [ 1, 1, 2, 0, 0, 1, 2, 2, 1, 1, 0 ], [ 1, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0 ] ); my @ControlNames = ('Label', 'Textbox', 'Button');
@ControlMatrix describes controls on a page, with the first dimension being the control (corresponding to the entries in @ControlNames) and the second dimension being the field requirements for the control. A 1 denotes a "required" field, a 2 denotes an "optional" field, and a 0 denotes a field not included on this control.
What I'd like to do is output a 2D array of all the possible permutations of optional fields for each control.
For example, for the first control this would output:
( [ 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1 ], [ 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1 ], [ 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 1 ], [ 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1 ], [ 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1 ], [ 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 1 ], [ 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1 ], [ 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1 ] )
Anyone have an elegant way to do this?
Shayk
In reply to Permutation algorithm? by Shayk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |