Algorithm to fill slots
- by Peter Lang
I am searching for an algorithm to fill several slots, which are already filled to some level.
The current levels and the available quantity to fill are known
Resulting levels should be as equal as possible, but existing level cannot be reduced
Slots are filled from left to right, so left slots get higher level if equal level is impossible
The image above shows six examples, each column represents a slot. The grey area is already filled, the blue are is the expected position of the new elements.
I could iterate through my slots and increase the quantity on the lowest slot by 1 until the available quantity is consumed, but I wonder about how to actually calculate the new filling levels.
I am going to implement this with SQL/PL/SQL, other code is just as welcome though :)