I am working out my last size optimization and I don't get the index function.

Let's take an example: KQQR-K

The array should be built (as far as I understand) this way:

- Code: Select all
`1. K = 0...9 (the unique triangle)`

2. Q1 = 0...63

3. Q2 = Q1 + 1...63

4. R = 0...63

5. K = 0..63

First this formula I get from a previous post does not seem to give the right index:

- Code: Select all
`ix = q1 + q2*(q2-1)/2`

Testing in delphi code:

- Code: Select all
`for q1 := 0 to 63 do`

for q2 := q1 + 1 to 63 do

begin

ix = q1 + q2*(q2-1)/2 // gives the wrong index

end;

How should I calculate the index for the delphi example?

And after that, how should I calculate the index for the 5-piece example?