Re: Creating all combinations of a dynamic sequence
- Posted by PeteE Jul 02, 2010
- 1103 views
As long as sMySeq remains two-dimensional, you could use a sequence to keep track of which index you are in for each combination. After building a combo, increment the rightmost index, and carry into the left index if rolls over, just like addition. When you can't carry past index 1, you're finished.
integer finished sequence sCombos, indices, tmp finished = 0 sCombos = {} indices = repeat(1, length(sMySeq)) tmp = indices while not finished do ? indices for i = 1 to length(indices) do tmp[i] = sMySeq[i][indices[i]] end for sCombos = append(sCombos, tmp) for i = length(indices) to 1 by -1 do if indices[i] < length(sMySeq[i]) then indices[i] += 1 exit end if indices[i] = 1 if i = 1 then finished = 1 end if end for end while