/* test_combinations.c generate all combinations of n things taken m */ /* at a time */ #include #include #include "combinations.h" /* last = combinations(n, m, vn[], vm[], &first); */ /* return is 0 if more combinations to come. 1 if this is last */ /* n is for n things n! / ((n-m)! m!) combinations */ /* m is for m at a time */ /* vn must be the n items, unchanged by comb (can by pointers or indices) */ /* vm must be of size m items, the returned combination each call */ /* first must be 1 the first call, then set to zero internally */ int main(int argc, char *argv[]) { int n, m, first, last; int v3[4] = {1, 2, 3, 4}; int v2[2]; int v6[6] = {1, 2, 3, 4, 5, 6}; int v[6]; int i; printf("test_combinations.c running \n"); first = 1; last = 0; n = 4; m = 2; while(!last) { last = combinations(n, m, v3, v2, &first); printf("combinations(n=%d, m=%d, last=%d, %d %d \n", n, m, last, v2[0], v2[1]); } printf("\n"); first = 1; last = 0; n = 6; m = 3; while(!last) { last = combinations(n, m, v6, v3, &first); printf("combinations(n=%d, m=%d, last=%d, %d %d %d \n", n, m, last, v3[0], v3[1], v3[2]); } printf("\n"); printf("many cases n=6, m=0 to 7 \n"); n = 6; for(m=0; m<=7; m++) { first = 1; last = 0; while(!last) { last = combinations(n, m, v6, v, &first); printf("combinations(n=%d, m=%d, %d", n, m, v[0]); for(i=1; i