How to calculate an index into a binomial coefficient table from the base indexes
The binomial coefficient formula is defined as:
Total Number Of Unique Combinations = N! / ( K! (N - K)! )
where N is defined as the total number of values and K is the grouping number.
The following is a simple table that is bound by the binomial coefficient where N is 6 and K is 4:
1234 1235 1236 1245 1246
1256 1345 1346 1356 1456
2345 2346 2356 2456 3456
What I am trying to figure out, is if there is a formula that can be used to calculate an index to a table entry based upon that number. So, for example, if the number is 1245, then the formula should return the value 4 because it is the 4th entry in the table above. Another example is for 1356, the formula should return 9 since it is the 9th entry in the table.
Does anyone know of a formula, or can come up with a formula to calculate this?
I am writing a class that will be using N and K as inputs. I have come up with a way to do this by iterating through all of the possibilities and storing values into an index tables, but before publishing this technique I thought I would try to find a better way with a mathematical formula.
Re: How to calculate an index into a binomial coefficient table from the base indexes
Since no one was able to answer my question, I decided to look into it and came up with a nice efficient solution that does not use much memory which has just been posted to my blog. The solution includes a download file that contains 2 C# projects that implement a generic C# class that manages a table of any type of objects along with translation functions that convert between the underlying indexes and the position of the object within the table as well as the reverse function that converts between the position of the item within the table to yield the underlying indexes. The other project tests out the code which shows how to use the class as well as proves that it works correctly. See:
Tablizing The Binomial Coefficient | Just another WordPress.com site