in reply to Combinatorial problem

From your description and from your code it is not clear to me whether or not duplicates are allowed but if not check this thread how to chose k out of n elements in turn. Then all you need is to calculate the sum of all combinations.