A group consists of 6 students (3 boys and 3 girls) and one teacher. In how many ways can the 7 people sit in a row if boys cannot sit together and girls cannot sit together?
If the teacher sits 1st or 7th, then the possible seating arrangements
of students by sex are TBGBGBG or TGBGBGB or their reversals.
That's 4 arrangements by sex
If the teacher sits 2nd or 6th, then the possible seating arrangements
of students by sex are BTGBGBG, GTBGBGB, and their reversals.
That's 4 arrangements by sex
If the teacher sits 3rd or 5th, then the possible seating arrangements
of students by sex are BGTBGBG, GBTBGBG, BGTGBGB or GBTGBGB and their reversals. That's 8 arrangements by sex
If the teacher sits 4th, then the possible seating arrangements of students
by sex are BGBTGBG and its reversal. That's 2 arrangements by sex,
That's 4+4+8+2=18 arrangements by sex.
For each of those 18 arrangements by sex, there are 3! ways to arrange
the girls and 3! ways to arrange the boys,
Answer 18·3!·3! = 18·6·6 = 648 ways.
Edwin