List<List<WeightedGroupItem>> InitializePermutations(List<WeightedValue> groups)
{
PSDebug.Log ("Initialize permutations: {0}", groups.ToDebugString ());
var templates = new List<List<WeightedGroupItem>> ();
var numPerms = 1;
var digits = new int[groups.Count];
for (int i = 0; i < groups.Count; i++) {
var item = groups [i];
var supplements = _supplements (item);
supplements.ForEach (spm => spm.Weight *= item.Weight);
numPerms *= digits [i] = supplements.Count;
templates.Add (supplements);
}
var idx = new GenericNumber (digits);
var perms = new List<List<WeightedGroupItem>> (numPerms);
for (var i = 0; i < numPerms; ++i) {
var row = new List<WeightedGroupItem> ();
perms.Add (row);
for (var digit = 0; digit < idx.Value.Length; ++digit) {
row.Add (templates [digit] [idx.Value [digit]]);
}
idx.Incr ();
}
return perms;
}