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.