Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Algorithmen, Datenstrukturen und Klassendesign (https://www.delphipraxis.net/78-algorithmen-datenstrukturen-und-klassendesign/)
-   -   Delphi Generation of Multiple Set Combinations (https://www.delphipraxis.net/194442-generation-multiple-set-combinations.html)

danten 21. Nov 2017 10:05

Generation of Multiple Set Combinations
 
Liste der Anhänge anzeigen (Anzahl: 1)
Hello,
how to create a generator of all combinations of three array groups.
I need all the combinations, always from all three groups.
Thank you

Sample of the program in the image.

SProske 21. Nov 2017 10:18

AW: Generation of Multiple Set Combinations
 
What exactly do you have problems with? Nested looping over all 3 arrays should be sufficient.
Delphi-Quellcode:
for I := Low(Array1) to High(Array1) do
  for J := Low(Array2) to High(Array2) do
    for K := Low(Array3) to High(Array3) do
      WriteLn(Format('%s-%s-%s', [Array1[I], Array2[J], Array3[K]]));

danten 21. Nov 2017 10:48

AW: Generation of Multiple Set Combinations
 
Thank you,
the problem is to load the array array from edit.

Code:
Delphi-Quellcode:
procedure TFormGenerate.Generate;
var
  i1,i2,i3 : Integer;
  array1,array2,array3: array of string;
begin
  array1 := [editArray1.Text];
  array2 := [editArray2.Text];
  array3 := [editArray3.Text];

  for I1 := Low(Array1) to High(Array1) do
  for I2 := Low(Array2) to High(Array2) do
    for I3 := Low(Array3) to High(Array3) do
      Memo1.Lines.Add(Format('%s-%s-%s', [Array1[I1], Array2[I2], Array3[I3]]));
end;
Result = A,B,C,D-1,2,3,4,5,6-X1,X2

Delphi-Quellcode:
procedure TForm27.Generate;
var
  i1,i2,i3 : Integer;
  array1,array2,array3: array of string;
begin
  array1 := ['A','B'];
  array2 := ['1','2','3'];
  array3 := ['X1','X2'];

  for I1 := Low(Array1) to High(Array1) do
  for I2 := Low(Array2) to High(Array2) do
    for I3 := Low(Array3) to High(Array3) do
      Memo1.Lines.Add(Format('%s-%s-%s', [Array1[I1], Array2[I2], Array3[I3]]));
end;
Result =
A-1-X1
A-1-X2
A-2-X1
...
B-2-X2
B-3-X1
B-3-X2

SProske 21. Nov 2017 11:44

AW: Generation of Multiple Set Combinations
 
You need to split the string, like

Delphi-Quellcode:
var
  array1,array2,array3: TArray<string>;
begin
  array1:= string(editArray1.Text).Split([',']);
  ...

danten 21. Nov 2017 11:59

AW: Generation of Multiple Set Combinations
 
Zitat:

Zitat von SProske (Beitrag 1386794)
You need to split the string, like

Delphi-Quellcode:
var
  array1,array2,array3: TArray<string>;
begin
  array1:= string(editArray1.Text).Split([',']);
  ...

Yes, that's exactly it.
Thank you very much.


Alle Zeitangaben in WEZ +1. Es ist jetzt 22:53 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz