Let's say we have a grouping of people as such:

   Group People
1      1     40
2      2     40
3      3     43
4      4     15
5      5     41
6      6     10
7      7     23
8      8     17
9      9     32
10    10     31
11    11     21
12    12     12
13    13     25

There are 350 people and the goal of this problem is to group those people into "tables" of size 9.


-Make sure that all people are sitting with at least one other person of their original group

-It is best to have 9 people from the same group at the same table but obviously that will not be possible after dividing groups enough times.

-If one person cannot be grouped with another person of their original group, that is okay, but only at the end of the tabling.

-There are 350/9 = 38.88889 possible tables, so we round up to 39 possible tables. The 39th table will have less than 9 people.

Any ideas for the solution of this problem?


Here's a solution where your first rule is prioritized over your second rule:

enter image description here

For each group, the column "Group tables" has the number of tables exclusively occupied by that group, "Leftovers" has the number of people from that group which are not at a group table, and the column "Tables with leftovers" gives the distribution of the leftovers among the remaining tables.

  • $\begingroup$ Thank you for answering! This is a great solution. I am also interested in how you solved other than doing a "sudoku-like" solution? Any way to generalize this solution? $\endgroup$ – user111417 Aug 7 '17 at 20:59
  • $\begingroup$ I just used some general principles and a little tinkering. E.g. "If a leftover is 1, add a group table to the leftover", "If a leftover is 8 or higher, break up the leftover into smaller pieces", "Leftovers less than 4 cannot be broken up", etc. I don't immediately see a general solution method other than using such principles and brute force. $\endgroup$ – Jens Aug 7 '17 at 22:36
  • $\begingroup$ Thank you! I hope to find a more general solution, but I like the brute force that's involved sometimes, too. $\endgroup$ – user111417 Aug 8 '17 at 20:09

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.