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


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
    group 2

But what if group size is ie. 7?


if ID mod N == $0$ then

group $1$

else if ID mod N == 1 then

group $2$


else if ID mod N == $5$ then

group $6$


group $7$


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.