0

OK I'll try to explain what I'm trying to do...

I've got 16 numbers in an array and I want to find out the best way of adding any combination of these (it can be 2 of them, 5 of them or all of them) to get as close to a possible value as possible.

For example, I want to get to 1000 as my value - I could do this by adding 500 + 700 = 1200 or by adding 300 + 300 + 450 = 1050. Clearly the 1050 is closer but uses 3 values - this doesn't matter but I can only figure out how to add the numbers in order (e.g. value1+value2+value3...+value15+value16) I can't work out how it would take value1+value3+value15 over just value1+value2.

Any thoughts out there or am I trying to do something too clever?!