This is not linked to Delphi, but to programming in general. I've been
trying to write a table (matrice) of combinations of zeroes and ones. The
number of combinations is 2^n, so the matrix for n=2 would be
11
10
01
00
I've been trying to do this by the following procedure, with no luck so far.
Can anyone help?
CONST max = 10; { 2^10 = 1024 }
TYPE matrice = ARRAY[1..max,1..1024] OF BYTE;
PROCEDURE Combinations(n,pos,start,stop: Integer; VAR M: matrice);
{ pos - horisontal position in the matrice
start - starting vertical position
stop - ending v.p.
}
VAR
i,counter: CARDINAL;
BEGIN
counter := 0;
FOR i := start TO stop DO
INC(counter);
IF counter <= (stop - start + 1) DIV 2 THEN
M[pos,i] := '1'
ELSE
M[pos,i] := '0'
END;
IF n DIV 2 > 1 THEN BEGIN
Combinations(n DIV 2, pos+1, start, n DIV 2, M);
Combinations(n DIV 2, pos+1, start+(n DIV 2), n, M)
END
END;
_______________________________________________
Delphi mailing list
[EMAIL PROTECTED]
http://ns3.123.co.nz/mailman/listinfo/delphi