Issue
I want to divide a given number to wholenumbers and round off the first digit if the divisor was not a factor of the dividend.
Eg. My divisor shall always be 24.
dividend(d) = 4.
ans = array(1, 1, 1, 1);
d = 10.
ans = array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1);
d=24.
ans = array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);
- - - - - - Now here comes the twist. -- - - - - - -
d = 25.
ans = array(2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);
d = 35.
ans = array(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);
d = 79.
ans = array(4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3);
While I'm at it, let me also describe what I am trying to achieve from this..
I want to automate a task that shall perform a specific operation on a given no of objects (d which shall vary(read increase) over time.).
Now I shall be running a cron every hour daily, which gives me a constant divisor of 24 if I wish to balance/distribute the no objects on which the task has to run each day.
I have searched this division technique and found this question which was somewhat close to what i needed, though on how to implement it in php I am a bit lost.
Solution
Something like:
$x = floor($d / 24);
$y = $d % 24;
$ans = array_fill(0, 24, $x);
if ($y > 0)
array_splice($ans, 0, $y, array_fill(0, $y, $x+1));
$ans = array_filter($ans);
Answered By - Mark Baker