I'm working on this application that generates a table layout based on some criteria. The criteria consists of these things
- A list of guests
- The amount of tables
- The amount of dinner courses
- The type of algorithm
- Place guests at table at random
- Place guests at a unqiue table each course
- Place guests at a table with other unmet/unique guests each course
Right now I'm looking for the formula to calculate the constraint for the last algorithm (nr 3). After spending some time googling I found a formula for combinations/permutations, though it only works when the maximum amount of guest per table is less then three.
$$ \frac{n!}{r!(n − r)!} $$
In my cause I use r as the amount of guests and n as the amount of guest per table
( e.g. ceil( guest count / table count ) )
For example, With 4 guests and 3 tables, n=4 and r=2, the formula returns 6. Which matches my calculations
12 23 34
13 24
14
Same for 6 guests and 3 tables, n=6 and r=2, the formula returns 15. This also matches the calculations
12 23 34 45 56
13 24 35 46
14 25 36
15 26
16
But when the guests per table increases, the formula returns unwanted results. For example, n=7 and r=3, returns 35. But my calculation comes down to 7 combinations
123 246 356
145 257 347
167
I was hoping if someone could help me find or alter this formula so it matches these three calculations. Thus honoring the constraint:
maximum amount of combinations where each number can only be returned once in combination with the other numbers.
Thank you for your time