The Scenario: I'm writing a method that will calculate the total number of items. Then, if the item count is over 25, it needs to go into a second package, and so and so on.
What I want:
1) Calculate the number of total items
2) Loop through the total number of items and add the weight of each item until it reaches 25, then start a new package.
So if I have an order with 53 items:
20, 1lb widgets
25, 2lb widgets
8, 3lb widgets
Ideally, I would have the following result.
3 Total packages.
Pkg #1: Would have 25 items with a weight of 30 lbs. (201lb + the 52lb to fill up the first box).
Pkg #2: Would also have 25 items with a weight of 55 lbs. (202lb + the 53lb to fill up the second box).
Pkg #3: Would have the remaining 3 items with a weight of 15lbs.
My problem is that for some reason, I cannot wrap my head around this concept.
Any tips, tutorials or advice is welcomed.