with some c++ ish pseudocode that kinda might apply and be useful..
Sorry its ugly:
for (int i=0; i<numDestinationRows; i++)
{
toTransfer = floor ( moneyTotal / numDestinationRows );
if ( i < ( moneyTotal % numDestinationRows ) )
{
toTransfer++;
}
if ( ( destinationRowMoney[i] > toTransfer ) && ( i+1 == numDestinationRows ) )
{
transfer( destinationRowID[i] , ( destinationRowMoney[i] -
toTransfer ) , destinationRow[0] );
i -= numDestinationRows;
}
else if ( destinationRowMoney[i] > toTransfer )
{
transfer( destinationRowID[i] , ( destinationRowMoney[i] -
toTransfer ) , destinationRow[i+1] );
}
}
floor is round down
% is modulus, and it returns the remainder of the first number divided
by the second.
transfer(from,amount,to) - a mythical function
not gonna lie, im pretty... inebriated.. but I don't drink ;-)
I can't think straight enough to give exactly what I'm thinking. but
this is a good pseudo start
Greg