// combinations.java generate all combinations of n things taken m at a time // return is false if more combinations to come. true 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 // vm must be of size m items, the returned combination each call // combinations(n,m) must be instantiated for each new series of combinations // then more = comb(vn,vm) vn all index, vm m index, loop until more=false // see sample use in test_combinations.java public class combinations { private int n, m; int c[]; // the combination array int pos; // position of variable being moved, 0 to n-1 int var; // variable being moved, 0 to m-1 int mov; // variable starting move, 0 to m-1 int empty = -1; // mark empty space boolean first; public combinations(int n, int m) { this.n = n; this.m = m; c = new int[n]; for(int i=0; in) { System.out.println("bad parameters to comb, n="+n+", m="+m); return true; } if(first) { first = false; for(int i=0; i