New Year's Countdown Day 8: Eight Seated People

Eight people are sitting around a circular table. In how many ways can they reseat themselves so that nobody is seated to the immediate right of the same person as before?

As an explicit example, if they were originally seated as follows: A H B G C F D E \quad \, \, \ \text{A} \, \, \quad \\ \quad \text{H} \quad \, \, \ \ \ \ \text{B} \quad \\ \text{G} \quad \quad \quad \, \, \ \text{C} \\ \quad \text{F} \quad \, \, \ \ \ \ \text{D} \quad \\ \quad \, \, \ \text{E} \, \, \quad \\ then they can reseat themselves as follows, and no one would be sitting to the right of the same person as before: A B H C G D F E \quad \, \, \ \text{A} \, \, \quad \\ \quad \text{B} \quad \, \, \ \ \ \ \text{H} \quad \\ \text{C} \quad \quad \quad \, \, \ \text{G} \\ \quad \text{D} \quad \, \, \ \ \ \ \text{F} \quad \\ \quad \, \, \ \text{E} \, \, \quad \\ Details and Assumptions:

  • Arrangements that are rotations of each other are considered the same.
  • Arrangements that are reflections of each other are considered distinct.


The answer is 1625.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

4 solutions

Hu Yufan
Dec 19, 2017

我们将A除外,原问题化为F(7)的子问题,将A插回,A不能在B的右边与H的左边,A只有5个位置,5F(7)。
考虑BH相连的情况,将BH当作一个位置,此时A有6个位置,6F(6)。
考虑A在BC,CD,DE,EF,FG,GH之间,6F(6)。
考虑BH相连,并且A在BC,CD,DE,EF,FG,GH之间,6F(5)
F(8)=5F(7)+6F(6)+6F(6)+6F(5)
F(n)=(n-3)F(n-1)+2(n-2)F(n-2)+(n-2)F(n-3)
F(2)=0,F(3)=1,F(4)=1,F(5)=8,F(6)=36,F(7)=229,F(8)=1625


I programmed your solution for a larger N. Python: https://repl.it/@asdera1234/Dynamic-Table-Problem-Solver

Patrick He - 3 years, 5 months ago

What he's saying is : We exclude A, then the original question transform into the question of F(7). Plug A back, A can't sit right next to B or left next to H, so A only have 5 spots, 5F(7). Take "if BH is connected into cosideration", we regard BH as a single position. Now A has 6 position, 6F(6). Considering "if A between BC, CD, DE ,EF, EG, GH", 6F(6). Considering BH is connected, meanwhile A is between BC, CD, DE, EF, FG, GH, then 6F(5). F(8)=5F(7)+6F(6)+6F(6)+6F(5) F(n)=(n-3)F(n-1)+2(n-2)F(n-2)+(n-2)F(n-3) F(2)=0,F(3)=1,F(4)=1,F(5)=8,F(6)=36,F(7)=229,F(8)=1625

Jacob Hu - 3 years, 5 months ago

Log in to reply

I believe his recurrence relation, particularly after you explained it so well, but I'd like a little more justification for one of the moves that he makes. What gives him the right to stick two letters together, and treat them as if they were a single "person", allowing him to treat the number of permissible arrangements, that include one or two such "double persons," as either F(n - 1) or F(n - 2)?

Nicholas Palevsky - 3 years, 5 months ago

Log in to reply

Not the most elegant explanation but hopefully convincing:

Let (*n) be the objective that after rearrangement of n persons no person remains to the right of the same person as before rearrangement. Let F(n) be the number of arrangements that satisfy (*n).

After removing A he then looked for arrangements of (BCDEFGH) which would allow him to place A in some position which meant the resulting arrangement of (ABCDEFGH) satisfied (*8)

First, for any of the F(7) permutations of (BCDEFGH) which satisfy (*7) he can place A in 5 positions to satisfy (*8).

Now onto the complications...

Next and in more detail, any arrangement of (BCDEFGH) which ends up with HB does not satisfy (*7). However, let HB = X and consider arrangements of (XCDEFG) satisfying (*6) e.g. (DFXECG). Replacing X with HB gives us an arrangement which still does not satisfy (*7) on (BCDEFGH). However, first inserting A in any of the 6 positions in e.g. (DFXECG) and then replacing X with HB gives us an arrangement which does satisfy(*8) ...

...since H is not to the right of G [else X would be to the right of G - violating (*6)], similarly C is not to the right of B; A is not the right of H nor left of B [since the last step was replacing X with HB]; the rest following trivially from (*6).

So far we have

F(8)=5F(7)+6F(6)+...?...

Next replace BC with X and consider arrangements satisfying (*6) on (XDEFGH). For each of these F(6) arrangements, replace X with BC and then place A in between B and C. So we've found a new set of F(6) permutations satisfying (*8). You can convince yourself that none of these were covered in the earlier arrangements found. Similarly by replacing each of the pairs CD, DE ,EF, EG, GH with X we get for each pair an additional F(6). So 6F(6) in total.

Penultimately replace HB with X and CD with Y and find arrangements satisfying (*5) on (XYEFG). For each of these F(5) arrangements then revert X and Y and place A in between C and D. Similarly for HB with the pairs DE,EF and FG for a total of 4F(5).

Finally, to count arrangements of (ABCDEFGH) containing HBAC: as usual remove A. Replace HBC with Z. Find arrangements of (ZDEFG) satisfying (*5). Revert Z to HBC and insert A between B and C. This and similarly for GAHB give the final 2F(5) arrangements.

{{ Note: Hu Yufan combined the previous two paragraphs, perhaps with the intuition that we are replacing 4->2 letters or 3->1 letter to end up with the same total of letters at the end, and each time only have one way to use this to construct an arrangement satisfying (*8). Or perhaps substituting HB->X and then XC->Z, in some sense replacing 4 letters (H,B,X,C) with two (X,Z).}}

You can convince yourself that there are no other 7-arrangements where we could insert A to make a (*8) arrangement.

So

F(8) = 5F(7) + 6F(6) + 6F(6) + 4F(5) + 2F(5). This gives the recurrence relation

F(n) = (n-3)F(n-1) + 2(n-2)F(n-2) + (n-4)F(n-3) + 2F(n-3)

For which my construction breaks on account of the "(n-4)" when n is 3, but F(3-3) is likewise undefined so it can be simplified as we would like to...

F(n) = (n-3)F(n-1)+2(n-2)F(n-2)+(n-2)F(n-3) valid for n > 3.

Then we find by computation F(1)=F(2)=0, F(3)=1 and by recurrence the rest.

Daniel Singarajah - 3 years, 5 months ago

ni shi zhen de pi

Yinchen Wu - 3 years, 5 months ago
Ron van den Burg
Dec 23, 2017

Say there are n persons. Let F(n) be the number of allowed arrangements with n persons. So we are looking for F(8).

(1) There are ( n 1 ) ! (n-1)! seatings that are rotationally different. (Although most of them are not allowed).

(2) We can reduce all these seatings into groups of sequences: the candidate rearrangement a b d e f g c h abdefgch becomes { d e f g } { c } { h a b } \{defg\}\{c\}\{hab\} , a group of 3 sequences. With sequence, I will mean a (maximum) list of persons who are sitting next to each other in the original seating. Note that we may have to put the tail and the head into one sequence, as in the example above. There are ( n k ) {n \choose k} distinct groups of k k such sequences (choose k k persons to start a new sequence). Each such a group of k k sequences can be arranged in F(k) ways (other arrangements of the k k sequences wouldn't "break" the seating in k k sequences, but instead consist of k 1 k-1 or even less sequences). The only exception is the sequence of all n n persons. The ( n 1 ) {n \choose 1} possibilities for a single sequence a 1 a 2 . . . a n {a_1a_2...a_n} are all rotational the same.

Combined, we get 1 + k = 3 n ( n k ) F ( k ) = ( n 1 ) ! \displaystyle 1 + \sum_{k=3}^n {n \choose k}*F(k)=(n-1)!

We can now finaly resolve the F ( n ) F(n) recursively: F ( 1 ) = 1 , F ( 2 ) = 0 , F ( 3 ) = 1 , F ( 4 ) = 1 , F ( 5 ) = 8 , F ( 6 ) = 36 , F ( 7 ) = 229 , F ( 8 ) = 1625 F(1)=1, F(2)=0, F(3)=1, F(4)=1, F(5)=8, F(6)=36, F(7)=229, F(8)=1625 .

So the final answer to this question is: 1625 \boxed{1625} .

Rephrasing my original solution: Take a circular strip with n letters A, B, C, ... written on it. Cut the strip k { 0 , 1 , . . . , n } k\in\{0, 1, ..., n\} times between two letters into k k pieces. This can be done in ( n k ) n \choose k ways. Now rearrange all pieces of the strip so that it represents a seating rearrangement without unnecessary cuts. A cut is unnecessary if both sides of a single cut are again neighbours after rearrangement. Such rearrangement can be done in F ( k ) F(k) ways. This makes F ( 1 ) = F ( 2 ) = 0 , F ( 0 ) = 1 F(1)=F(2)=0, F(0)=1 and F ( 8 ) F(8) the answer we look for. Now all rearrangements are a one-to-one mapping to all ( n 1 ) ! (n-1)! rearrangements. So

Σ k = 0 n ( n k ) F ( k ) = ( n 1 ) ! \displaystyle \Sigma_{k=0}^n {n \choose k} F(k)=(n-1)!

By using this formula with n = 3 , 4 , . . . , 8 n=3, 4, ..., 8 we find F ( 3 ) = 1 , F ( 4 ) = 1 , F ( 5 ) = 8 , F ( 6 ) = 36 , F ( 7 ) = 229 F(3)=1, F(4)=1, F(5)=8, F(6)=36, F(7)=229 and finally F ( 8 ) = 1625 F(8)=\boxed{1625} .

Ron van den Burg - 3 years, 5 months ago

Log in to reply

Consider a variant of the problem--number of ways to reseat themselves so that no one is next to his earlier neighbour. Thnks

diwakar kumar - 3 years, 3 months ago
Nicholas Palevsky
Dec 18, 2017

A guess, using Stirling numbers of the first kind: The reflected arrangement given as an example in the problem is one solution, and then every transformation to all other solutions — choosing, say, 'A' as the fixed point — count up to |s(7,3)|. So then 1 + 1624 would add up to 1625. But I can't quite figure out how partitioning the other seven letters into three cycles works out.

As for how I actually got the solution, it took me just a few minutes to write a recursive program in Ruby to count the solutions , but Ruby doesn't seem to format in Brilliant. It would take me quite a bit longer to translate the program into Python, which I really don't know.

Nicholas Palevsky - 3 years, 5 months ago

Log in to reply

Here is the Ruby unformatted: GUESTS = (0...8).to_a

def seat(arr) if arr.length == 8 (arr.last == 7) ? 0 : 1 else nxt = (arr.last + 1) % 8 cands = (GUESTS - (arr | [nxt])) cands.inject(0) do |count,e| new arr = arr + [e] count + seat(new arr) end end end

Nicholas Palevsky - 3 years, 5 months ago

In sage, which works via Python, there is a function Arrangements which you can use to make a list of all permutations of a given list. Using the permutations of [1,...,7] one can easily check whether this leads to an allowed permutation. (The original order is [0,...,7] and 0 stays in its place to cancel out rotations.)

Sam Adriaensen - 3 years, 5 months ago

Log in to reply

Yes, there is something similar in Ruby. It isn't hard to program this problem, and there would be several ways to do it.

Nicholas Palevsky - 3 years, 5 months ago

" nobody is seated to the right of the same person as before".

Does it mean among all arrangements before, or just the previous arrangement?

X Y - 3 years, 5 months ago

Log in to reply

It means from how they were originally seated, so in the example, when the people reseat themselves, A can't be to the right of B, B can't be to the right of C, and so on.

Steven Yuan - 3 years, 5 months ago

Log in to reply

I see! I interpreted the question wrong. Thanks!

X Y - 3 years, 5 months ago

I don't understand why Stirling numbers work here. If so, I would expect the Stirling numbers also explain the number of allowed seatings with 7 persons: s ( 6 , 3 ) = 225 |s(6,3)|=225 while F ( 7 ) = 229 F(7)=229 .

Ron van den Burg - 3 years, 5 months ago

This could be an easy solution:

from itertools import permutations

def check_rotation(l):
    for i in range(len(l)-1):
        if l[i+1]-l[i] == 1:
            return True
    return False 

n = 8
counter = 0;

for l in permutations(range(n)):
    if l[0] == 1:
        break
    if l[n - 1] == n-1:
        continue
    if not check_rotation(l):
        counter += 1

print(counter)

I would say this question is formulated incorrectly. "nobody is seated to the right of the same person as before" this tells that nobody gets to sit again with same person on a right as before. In a group of 8 people there are only 7 other people that could sit on a right, and any other additional combination would result to at least someone have same person sit on a right.

Jonas Skačkauskas - 3 years, 5 months ago

Log in to reply

How is this related to my answer?

Djordje Marjanovic - 3 years, 5 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...