[DUG] Make all possible unique combinations
John Bird
johnkbird at paradise.net.nz
Thu Dec 10 12:44:56 NZDT 2009
One way may be to put the data into a non-rectangular mutidimensional array.
Depends exactly what you mean by making all possible combinations, but I
imagine having the data in one array would allow you to generalise it most
easily.
Once its there there could be many clever ways using high() and low() to
have a general algorithm
from the Help on multi-dimendional arrays:
"you can create multidimensional dynamic arrays that are not rectangular.
The first step is to call SetLength, passing it parameters for the first n
dimensions of the array. For example,
var Ints: array of array of Integer;
SetLength(Ints,10);
allocates ten rows for Ints but no columns. Later, you can allocate the
columns one at a time (giving them different lengths); for example
SetLength(Ints[2], 5);
makes the third column of Ints five integers long. At this point (even if
the other columns haven't been allocated) you can assign values to the third
column--for example, Ints[2,4] := 6."
ex
for J := Low(A[I]) to High(A[I]) do
A[I,J] := IntToStr(I) + ',' + IntToStr(J) + ' ';
John
Subject: [DUG] Make all possible unique combinations
>I am looking for ideas to generate all possible combinations for the
>following arrays. I don't want to use for.. loops as number of arrays can
>change.
>
> const
> STGR : array[1..2] of string = ('A1', 'A2');
> STG1 : array[1..4] of string = ('B1', 'B2', 'B3', 'B4');
> STG2 : array[1..2] of string = ('C1', 'C2');
> .
> .
> STGN : array[1..2] of string = ('N1', 'N2');
>
>
> I have an algorithm to this but was wondering if there are other
> simpler/better/quicker ways to do this.
>
> Regards
>
> Sandeep
>
>
>
>
> _______________________________________________
> NZ Borland Developers Group - Delphi mailing list
> Post: delphi at delphi.org.nz
> Admin: http://delphi.org.nz/mailman/listinfo/delphi
> Unsubscribe: send an email to delphi-request at delphi.org.nz with Subject:
> unsubscribe
More information about the Delphi
mailing list