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; } }
Sorry for the dumb question, I am not really good at vex, but want to get better. Thanks everyone .