Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

determining which numbers in an array equal a specific sum

Tags:

algorithm

vba

I am presenting this question as a general math problem. I am going to tag it with Visual Basic, as the solution would likely be implemented in a spreadsheet.

I have a list of shipments with the number of widgets in each shipment. Each shipment was loaded on either Truck #1 or Truck #2. Given the total number of widgets on each truck, how can I determine which shipments were on each truck?

For example, here is the loading for total widgets in each truck:

Truck #1  83,240 
Truck #2  63,460 
         -------
         146,700

And here is a detailed shipment list.

SHIPMENT ID  QUANTITY 
90006           340 
93806         2,460 
93906        22,980 
92506         5,960 
96306         3,580 
96406         3,320 
96906         2,680 
97306         1,160 
99206         9,780 
95005        15,300 
95006         2,980 
96008        22,320 
95606        28,580 
90206         5,020 
90306         3,160 
94006         1,140 
94406         4,640 
94606         7,900 
98606         3,400 
            -------
            146,700 

Which shipments were in Truck #1 and Truck #2?

like image 323
user191688 Avatar asked Sep 16 '11 13:09

user191688


1 Answers

This is a variation of the subset sum problem. More information can be found on Stack Exchange's Math site. This problem is not trivial. One algorithm is described at the Wikipedia page. In your case, an exhaustive search is probably appropriate.

like image 170
Ishmael Avatar answered Sep 21 '22 22:09

Ishmael