Why don't you just always do the following order, MUCH easier to generate:
a - b,c,d
b - c,d,e
c - d,e,a
d - e,a,b
e - a,b,c
//aka
( 0 - 1,2,3 ) %5
( 1 - 2,3,4 ) %5
( 2 - 3,4,5 ) %5
( 3 - 4,5,6 ) %5
( 4 - 5,6,7 ) %5
I've created a generating form similar to the above but utilizing modulo in C. You can try it online here:
http://ideone.com/n6qBzN
Code for reference:
main() {
char *myString = "ABCDEFGHIJKLMNOP4583";
int characters = mystrlen(myString);
int i = 0;
while (i < characters) {
printf("%c", myString[i]);
printf(" - ");
int a = 1;
while (a <= characters-2) {
printf("%c, ", myString[(i+a)%characters]);
a++;
}
printf("\n");
i++;
}
}
int mystrlen(char *s) {//arbitrary function for determining number of characters in a string (your initial group set)
int i =0;
while (*s++) i++;
return i;
}
So you can see in the above code that the initial list of people groups is ABCDEFGHIJKLMNOP4583
and it generates the following table:
A - B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, 4, 5, 8,
B - C, D, E, F, G, H, I, J, K, L, M, N, O, P, 4, 5, 8, 3,
C - D, E, F, G, H, I, J, K, L, M, N, O, P, 4, 5, 8, 3, A,
D - E, F, G, H, I, J, K, L, M, N, O, P, 4, 5, 8, 3, A, B,
E - F, G, H, I, J, K, L, M, N, O, P, 4, 5, 8, 3, A, B, C,
F - G, H, I, J, K, L, M, N, O, P, 4, 5, 8, 3, A, B, C, D,
G - H, I, J, K, L, M, N, O, P, 4, 5, 8, 3, A, B, C, D, E,
H - I, J, K, L, M, N, O, P, 4, 5, 8, 3, A, B, C, D, E, F,
I - J, K, L, M, N, O, P, 4, 5, 8, 3, A, B, C, D, E, F, G,
J - K, L, M, N, O, P, 4, 5, 8, 3, A, B, C, D, E, F, G, H,
K - L, M, N, O, P, 4, 5, 8, 3, A, B, C, D, E, F, G, H, I,
L - M, N, O, P, 4, 5, 8, 3, A, B, C, D, E, F, G, H, I, J,
M - N, O, P, 4, 5, 8, 3, A, B, C, D, E, F, G, H, I, J, K,
N - O, P, 4, 5, 8, 3, A, B, C, D, E, F, G, H, I, J, K, L,
O - P, 4, 5, 8, 3, A, B, C, D, E, F, G, H, I, J, K, L, M,
P - 4, 5, 8, 3, A, B, C, D, E, F, G, H, I, J, K, L, M, N,
4 - 5, 8, 3, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O,
5 - 8, 3, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P,
8 - 3, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, 4,
3 - A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, 4, 5,