jeudi 3 août 2017

Advanced Conditional Random Number Generator in MS-EXCEL

In Excel, I have a table with items, each with a negative or positive value. I am wondering if there is a simple approach to selecting a random subset of integer numbers from the table whose sum could be 0 or close to it (lets say after k iterations).

Several of the solutions mentioned on stackexchange alluded to the (NUMBER/SUM_OF_NUMBER_COLUMN)*TARGET_SUM approach, but it does not work for all cases, [ex: if the sum is 0]

Eg:

In the image attached, you input the # of items to be selected and the target sum. The solution is expected to return a combination of the indicated # of items from the table [BEST SELECTION] such the the target sum is met or is close to it (+/-1 deviation is ideal).

As you can see only column 1 is guaranteed to be unique, i.e. there may be duplicate instances of item names (as seen in column 2), and/or different item names with the same value (as seen in column 3).

Example Table

I was able to implement something with a combination of INDEX(), RANDBETWEEN() and VLOOKUP(), to generate numbers but I could not check the sum requirement and for some reason VLOOKUP() only returned valid results for items with a positive value.




Aucun commentaire:

Enregistrer un commentaire