0
$\begingroup$

I have unknown number of items, each having ID (consecutive integer numbers), ie.

1,2,3,4,5,6,7,8,9,10,11,12,13,14,15...

I want to split above items into as equal size N groups as possible, using algorithm based on the ID.

Important! The input data is only:

  • X (group size)
  • ID of current item

The algorithm is simple when the group size is 2:

if ID mod 2 == 0 then
    group 1
else
    group 2

But what if group size is ie. 7?

$\endgroup$
0
$\begingroup$

if ID mod N == $0$ then

group $1$

else if ID mod N == 1 then

group $2$

$\ddots$

else if ID mod N == $5$ then

group $6$

else

group $7$

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.