Shayk has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Permutation algorithm?
by chromatic (Archbishop) on Oct 20, 2000 at 06:59 UTC | |
|
RE (tilly) 1 (not): Permutation algorithm?
by tilly (Archbishop) on Oct 20, 2000 at 13:14 UTC | |
|
RE: Permutation algorithm?
by Petruchio (Vicar) on Oct 20, 2000 at 16:39 UTC | |
|
Re: Permutation algorithm?
by Lexicon (Chaplain) on Oct 20, 2000 at 12:42 UTC | |
|
Why get all of the arrays?
by tedv (Pilgrim) on Oct 20, 2000 at 22:53 UTC |