[Solved] All array possibilities


I have taken the first permutation algorithm I found in wikipedia and implemented it in Delphi (2009); I hope that is what you are looking for:

type
  TIntegerArray = array of Integer;

procedure Permutation(K: Integer; var A: TIntegerArray);
var
  I, J: Integer;
  Tmp: Integer;

begin
  for I:= 2 to Length(A) do begin
    J:= K mod I;
    Tmp:= A[J];
    A[J]:= A[I - 1];
    A[I - 1]:= Tmp;
    K:= K div I;
   end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  K, I: Integer;
  A: TIntegerArray;
  S: string;

begin
  Memo1.Lines.Clear;
  for K:= 0 to 719 do begin
    A:= TIntegerArray.Create(14, 2, 4, 5, 6, 8);
    Permutation(K, A);
    S:= '';
    for I:= 0 to Length(A) - 1 do
      S:= S + Format('%3.d ', [A[I]]);
    Memo1.Lines.Add(S);
  end;
end;

solved All array possibilities