public static Summand[] GenerateSummands(uint n, uint k) { var combs = Generate(n, k); // TODO: compute multinomial coeffs here (length of array = k) var multinomialCoefs = new List <Tuple <uint[], ulong> >(); Summand[] result = new Summand[combs.Length]; uint[] array = new uint[n]; for (int i = 0; i < result.Length; i++) { result[i] = new Summand { Factors = (uint[])combs[i].Clone() }; for (int j = 0; j < n; j++) { array[j] = 0; } for (int j = 0; j < k; j++) { array[combs[i][j]]++; } Array.Sort(array); bool finded = false; foreach (var coef in multinomialCoefs) { if (Enumerable.SequenceEqual(array, coef.Item1)) { result[i].Coefficient = coef.Item2; finded = true; break; } } if (!finded) { result[i].Coefficient = Multinomial.PrimeNumbers(array); multinomialCoefs.Add(new Tuple <uint[], ulong>((uint[])array.Clone(), result[i].Coefficient)); } } return(result); }
public static Summand[] GenerateSummands(uint n, uint k) { var combs = Generate(n, k); // TODO: compute multinomial coeffs here (length of array = k) var multinomialCoefs = new List<Tuple<uint[], ulong>>(); Summand[] result = new Summand[combs.Length]; uint[] array = new uint[n]; for (int i = 0; i < result.Length; i++) { result[i] = new Summand { Factors = (uint[])combs[i].Clone() }; for (int j = 0; j < n; j++) array[j] = 0; for (int j = 0; j < k; j++) array[combs[i][j]]++; Array.Sort(array); bool finded = false; foreach (var coef in multinomialCoefs) if (Enumerable.SequenceEqual(array, coef.Item1)) { result[i].Coefficient = coef.Item2; finded = true; break; } if (!finded) { result[i].Coefficient = Multinomial.PrimeNumbers(array); multinomialCoefs.Add(new Tuple<uint[], ulong>((uint[])array.Clone(), result[i].Coefficient)); } } return result; }