Hola Rioja72.
Para sumar alguna idea te pongo un código que hasta donde probé funciona.
Dados los datos, genera todas las combinaciones posibles, aunque no necesariamente en el órden que mostras en tu ejemplo.
La cantidad de elementos de las listas, así como el número de elementos por grupos se ajustan con tres SpinEdits.
Te quedaría probarlo más a fondo y ver si te puede servir. (o al menos espero que te aporte alguna idea)
Código Delphi
[-]
type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
SpinEditLstA: TSpinEdit;
SpinEditLstB: TSpinEdit;
SpinEditNGrp: TSpinEdit;
StringGrid1: TStringGrid;
btMostrar: TButton;
procedure FormShow(Sender: TObject);
procedure btMostrarClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
MAXLSTA, MAXLSTB: Integer;
FGrupoA, FGrupoB, FParejas: Tstrings;
procedure Inicializar;
procedure Mostrar(NElem: Integer);
public
end;
var
Form1: TForm1;
implementation {$R *.dfm}
procedure TForm1.FormShow(Sender: TObject);
begin
FGrupoA:= TStringList.Create;
FGrupoB:= TStringList.Create;
FParejas:= TStringList.Create;
end;
procedure TForm1.Inicializar;
var
c,f,x: Integer;
begin
FGrupoA.Clear;
FGrupoB.Clear;
FParejas.Clear;
MAXLSTA:= SpinEditLstA.Value-1;
MAXLSTB:= SpinEditLstB.Value-1;
for x:= 0 to MAXLSTA do
FGrupoA.Add('A'+IntToStr(x+1));
for x:= 0 to MAXLSTB do
FGrupoB.Add('B'+IntToStr(x+1));
for f:= 0 to MAXLSTA do
begin
x:= f;
for c:= 0 to MAXLSTB do
begin
if x < MAXLSTA then
Inc(x)
else
x:= 0;
FParejas.Add(FGrupoA[x]+' '+FGrupoB[c]);
end;
end;
end;
procedure TForm1.Mostrar(NElem: Integer);
var
i,j,NGrp,ix: Integer;
begin
Inicializar;
for i:= 0 to 10 do
for j:= 0 to 10 do
StringGrid1.Cells[i,j]:= '';
NGrp:= (FParejas.Count) div NElem;
for ix:= 1 to NGrp do
StringGrid1.Cells[ix,0]:= 'Grupo '+IntToStr(ix);
ix:= 0;
for i:= 1 to NGrp do
for j:= 1 to NElem do
begin
StringGrid1.Cells[i,j]:= FParejas[ix];
Inc(ix);
end;
ix:= FParejas.Count-(NGrp*NElem);
if ix > 0 then
begin
StringGrid1.Cells[NGrp+1,0]:= 'Grupo ' + IntToStr(NGrp+1);
for i:= 0 to ix - 1 do
StringGrid1.Cells[NGrp+1, i+1]:= FParejas[FParejas.Count-ix+i];
end;
end;
procedure TForm1.btMostrarClick(Sender: TObject);
begin
Mostrar(SpinEditNGrp.Value);
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
FGrupoA.Free;
FGrupoB.Free;
FParejas.Free;
end;
end.
Saludos.
