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.
In reply to Re: Combinatorial problem
by hdb
in thread Combinatorial problem
by baxy77bax
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |