Solved
n choose k programming question
Posted on 1998-08-24
I am having difficulty implementing an "n choose k" function in C/C++. It seems like it is a recursive function, but mine is buggy for k greater than two.
The function should have parameters like:
nchoosek(int k, int n, int *in, int *out)
where "in" as an array of ints of length n and "out" is the resulting array of length [n!/k!*(n-k)!] *k.
For example, let in=[0 1 2 3] n=4 k=3, then
out=[0 1 2 0 1 3 0 2 3 1 2 3]
I am getting tired of fixing mine!
Thanks,
Dan