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; } } }

In reply to Re: Permutation algorithm? by Lexicon
in thread Permutation algorithm? by Shayk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.