Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Not exactly following your sequence of output, but following a sequence similar to the way binary numbers add up...</p> <pre><code>0001 0010 0011 0100 ... </code></pre> <p>The idea is simple: loop index values in an array indicating which character to use at the respective position to compose the output combination string. No recursion required.</p> <p>NextCombination updates the index array so the next combination is defined, it returns true as long as not all combinations are formed. False when back to all 0's.</p> <p>DefineCombinations accepts a string with chars to use (for example 'ABC') and a size of the combined string (eg: 3): this adds the following sequence to a memo:</p> <pre><code>AAA, AAB, AAC, ABA, ABB, ABC, ACA, ACB, ACC, BAA, BAB, BAC, BBA, BBB, BBC, BCA, BCB, BCC, CAA, CAB, CAC, CBA, CBB, CBC, CCA, CCB, CCC </code></pre> <p>Adapt as you wish.</p> <pre><code>function TForm1.NextCombination(var aIndices: array of Integer; const MaxValue: Integer): Boolean; var Index : Integer; begin Result:=False; Index:=High(aIndices); while not(Result) and (Index &gt;= Low(aIndices)) do begin if (aIndices[Index] &lt; MaxValue) then begin { inc current index } aIndices[Index]:=aIndices[Index] + 1; Result:=True; end else begin { reset current index, process next } aIndices[Index]:=0; Dec(Index); end; end; end; procedure TForm1.DefineCombinations(const Chars: String; const Size: Integer); var aIndices : array of Integer; Index : Integer; sData : String; begin try SetLength(sData, Size); SetLength(aIndices, Size); repeat for Index:=Low(aIndices) to High(aIndices) do sData[Index + 1]:=Chars[aIndices[Index] + 1]; memo1.Lines.Add(sData); until not(NextCombination(aIndices, Length(Chars) - 1)); finally SetLength(aIndices, 0); SetLength(sData, 0); end; end; </code></pre> <p>Let me know if I missed something from the original question.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload