# Math Help - round table 2

1. ## round table 2

4 married couples sit at a round table. How many ways can they sit if each couple must sit seperately?

There is a formula for this solution but I couldn't get it.

Always, always, start a new thread for a new question.

Using inclusion/exclusion $\sum\limits_{k = 0}^4 {\left( { - 1} \right)^k \binom{ 4}{k} \cdot 2^k \left( {7 - k} \right)!}$

2. ## Re: round table 2

4 married couples sit at a round table. How many ways can they sit if each couple must sit seperately?

There is a formula for this solution but I couldn't get it. I am sorry I wanted to make some edits to my former post but I couldn't I just wanted to past the formula but I also pasted some messages with it I am sorry

3. ## Re: round table 2

I don't have a clue about the equation to solve this but I managed to do it brute force with Python.

Code:
>>> import itertools
>>> couples = {0:1, 2:3, 4:5, 6:7}
>>> for k,v in couples.items():
couples[v] = k

>>> all_positions = list(itertools.permutations(range(8)))
>>> def is_valid(position):
if position[0] == couples[position[-1]]:
return False
for p in range(len(position) - 1):
if position[p] == couples[position[p+1]]:
return False
return True

>>> all_positions = [p for p in all_positions if is_valid(p)]
>>> len(all_positions)
11904
>>>
seems to be 11904

4. ## Re: round table 2

Originally Posted by russ123
I don't have a clue about the equation to solve this but I managed to do it brute force with Python.
Code:
>>> import itertools
>>> couples = {0:1, 2:3, 4:5, 6:7}
>>> for k,v in couples.items():
couples[v] = k
>>> all_positions = list(itertools.permutations(range(8)))
>>> def is_valid(position):
if position[0] == couples[position[-1]]:
return False
for p in range(len(position) - 1):
if position[p] == couples[position[p+1]]:
return False
return True
>>> all_positions = [p for p in all_positions if is_valid(p)]
>>> len(all_positions)
11904>>>
seems to be 11904

That is a gross over-count. There are only $7!=5040$ ways to seat eight people at a around table.

5. ## Re: round table 2

Sorry, I didn't know the exact positions of the seats didn't matter, that only the relative positions mattered then I can see how it's 7!

--- edit ---

I tried to correct my mistake and got a much lower figure: 1488
...but I wonder if it's right this time. If so then this will tell you the answer for any number of couples

Code:
from itertools import permutations

def check(config):
'''
return True if no couples are next to each other
False otherwise
'''
if config[0] == 0 or config[-1] == 0:
return False
else:
for x in range(len(config) - 1):
if config[x] == config[x + 1]:
return False
return True

while True:
couples = int(raw_input("couples: "))
all_configs = [0] + (range(1, couples) * 2)
all_configs = [c for c in list(permutations(all_configs)) if check(c)]
print len(all_configs)