public static void FallingFactorial() { //this example shows how to get falling factorial //use Combinatoric.FallingFactorial(n, r) for n!/r! Console.WriteLine(Combinatoric.FallingFactorial(10, 5)); }
//constructors //static methods static long count(IEnumerable <T> source, int length, CombinatoricModel model) { switch (model) { case CombinatoricModel.Normal: return(Combinatoric.FallingFactorial((long)source.Count(), length)); case CombinatoricModel.Repetition: return(((long)source.Count()).Power(length)); case CombinatoricModel.Distinct: var lookup = source.ToLookup(x => x); return(distinctCount(lookup.Select(x => x.LongCount()).OrderBy(x => x).ToList(), length, lookup.Count, source.Count() - length)); case CombinatoricModel.RepetitionDistinct: return(source.Distinct().LongCount().Power(length)); default: return(0L); } }