I’m trying to divide an integer N <= 12, which is a number of work days, to 12 months, so that if I divide 12 months into
periods of 1, 2, 3, 4 or 6 months, the number of days in these periods should be as equal as possible.
For example:
If N = 6, the array should look like this :
1 0 1 0 1 0 1 0 1 0 1 0 or 0 1 0 1 0 1 0 1 0 1 0
N = 4
1 0 0 1 0 0 1 0 0 1 0 0
N = 3
1 0 0 1 0 0 1 0 0 0 0 0
N = 2
1 0 0 0 0 0 1 0 0 0 0 0
edit:
what I mean by “as equal as possible” is that when I divide this array into periods, the number of work days in these periods shouldn’t differ by more than 1.
EDIT — Improved for the general case, assumed you were only asking for 1,2,3,4,6 as in question!
What you want is to modulate N by a given period. (My terminology is likely entirely wrong 😀 Should probably go read up on my high school physics again!)
Have some Ruby..
Output is:
Better now? 🙂