Algorithm to fill slots
Posted
by Peter Lang
on Stack Overflow
See other posts from Stack Overflow
or by Peter Lang
Published on 2010-05-26T09:56:38Z
Indexed on
2010/05/26
11:41 UTC
Read the original article
Hit count: 411
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 :)
© Stack Overflow or respective owner