static List <BitSet> Generate(int length, params int[] runs) { var list = new List <BitSet>(); BitSet initial = BitSet.Empty; int[] sums = new int[runs.Length]; sums[0] = 0; for (int i = 1; i < runs.Length; i++) { sums[i] = sums[i - 1] + runs[i - 1] + 1; } for (int r = 0; r < runs.Length; r++) { initial = initial.AddRange(sums[r], runs[r]); } Generate(list, BitSet.Empty.Add(length), runs, sums, initial, 0, 0); return(list); }