I'm trying to do a reverse binomial coefficient calculation in which I get a set of random combinations of (n,r), then I must be able to determine any n-Choose-r(n,r) in the set or subsets. For e.g. if user inputs following set: {(1,2,3) (1,2,4) (1,3,4) (2,3,4)}, the program must detect nCr(3,4).
To do so, First I obtain the
all_combinations = nCr(subset_length,input_set_length)
which in this case is nCr(3,4) = 4.
Then, I calculate the frequency of each element in form of [element:frequency] as follows.
fs = [1:3], [2:3], [3:3], [4:3]
Finally,
if (length(fs) != all_combinations ) return;
foreach(element in fs)
if( count(fs.elements) != subset_length ) return;
print 'found nCr:' + subset_length + ',' + input_set_length
frequency of all elements is equal to subset length, I conclude it's a full combination set.
However, it seems to be incapable of detecting complex cases. For example consider following case:
{(1,2,3) (1,2,4) (1,3,4)}
It's not hard to see there is a fixed element as 1 and a combination of nCr(3,2) in the subsets
{(2,3) (2,4) (3,4)}
I believe there should be better way to detect binomial coefficients recursively out there. Any help is highly appreciated.