1
$\begingroup$

I have this programming challenge I'm doing and I already have code, however I don't really understand it. I think that I need mathematical explanation of how it works, because the code is really easy.

What I'm doing is dividing a number $1 \le N \le 11$ to an array of $12$ elements, so that elements don't differ by more than one. Also when I divide this array into periods of $1$, $2$, $3$, $4$ or $6$ months the number doesn't differ by more than one in these periods.

Here's my algorithm:

d = 12 / N // average length of each interval

for (int i = 0; i < 12; i++){      if (12 - (i % d) > 11) {          array[i] += 1;      } } 

What I really don't understand is this line (12 - (i % d) > 11) . Why does this work ?

1 Answers 1