I am trying to solve a combinational sum issue in vex. So I have a given value of

**k**, lets say 16 and specific items in an

**array**, lets say {17,7,4,2,1}. I want Houdini to give me at least the first combination (ideal would be the shortest one) of items that results in

**k**as an array.

My not so charming start:

int iter = chi("iter"); int k = 16; int result; int array[] = {17,7, 4, 2, 1}; int comb[]; for(int n=0; n<iter ; n++) { append(comb, array[n]); result = sum(comb); if(result==k) { return; } }

**result**is not equal to

**k**, try another combination. But also limit the

**comb**array to max 3 items (I dont want a combination like {1+1+1+1+1+1+1...}. And if nothing is ever found, then it is allowed to expand the items count as long as it needs to find the first combination.

Sorry for the dumb question, I am not really good at vex, but want to get better. Thanks everyone .