This is a bit of a logic puzzle that I've been working on and I'm curious to see what kind of solutions the SO community comes up with. I have 24 randomly generated demand values, one for each hour of the day. I have a staff of 15, who each must work in 8 hours shifts, but may start at any hour of the day. I'm looking for the formula that will minimize the total difference in supply and demand for the 24 hour period. The result may look similar to the table below, given that the formula assigns a "1" for every hour in the staff's optimal eight hour shift.
Hour Demand Staff 1 Staff 2 ... Staff 15 Total Staff Difference
0 4 1 1 0 4 0
1 3 1 1 0 4 0
...
23 6 0 0 1 5 1