all groups > flash actionscript > february 2006 >
You're in the

flash actionscript

group:

Equally distribute numbers in a grid


Equally distribute numbers in a grid tmat311
2/2/2006 9:20:45 PM
flash actionscript:
Here's my dilema:

I'm working on a schedule that takes a total number of hours, then distributes
them evenly across 5 days AND a certain number of people. For example, I have
50 hours... that would divide up into 10 hours per day, and for 5 people, 2
hours per day per person. That's the easy part... divide the total number by
number of days, then divide that by number of people.

The problem I'm having is that they need to stay whole numbers. So, if the
total number is "40", the numbers get distributed so that some people have 2
hours on one day, then 1 hour on another, etc.

Right now, I've set up a grid of dynamic text boxes, then I loop through the
"number of people" boxes, adding 1 until all those boxes equal my total number:
person01 += 1;
hoursVar = person01 + person02 + person03 + person04 + person05;
if (hoursVar == totalHours) {
break;
}
... then I repeat that for each person. THEN I loop through the days of the
week for each person, until THAT total equals the total for each person. But
what ends up happening, is the lower numbers all congregate at the bottom of
the "people" list and at the end of the "days". I can move some of the dynamic
boxes around, so it mixes up a little... but it's still not a complete even
distribution.

Am I making ANY sense? :)
Many thanks for anyone who could offer some input!

Re: Equally distribute numbers in a grid Rothrock
2/2/2006 9:41:15 PM
I think you need to divide the people into fractional people! :)

AddThis Social Bookmark Button