I am looking for an algorithm to fill several slots that are already filled to some level.
- The current levels and the amount available for filling are known.
- The resulting levels should be as equal as possible, but the existing level cannot be reduced.
- Slots are filled from left to right, so left slots get a higher level if it is impossible to achieve an equal level.
Examples http://img695.imageshack.us/img695/6529/fill.png
The above figure shows six examples, each column is a slot. The gray area is already filled, blue is the expected position of the new elements.
I could iterate through my slots and increase the quantity in the lower slot by 1until the quantity is consumed, but I am wondering how to actually calculate the new fill levels.
I'm going to implement this with SQL/ PL/SQL, other code is also welcome :)
source
share