Eight different boys and five different girls are in a row. Girls are required to be next to each other. How many ways are there (the answer is $9!\times5!$)?
Cases[Permutations[Array[boy, 8]~Join~Array[girl, 5]], {___, girl[_],
girl[_], ___}] // Length
General::nomem: The current computation was aborted because there was insufficient memory available to complete the computation.
However, the above code indicates that there is not enough memory. What is the memory saving way to solve this problem? Feel free to correct the grammar mistakes and unidiomatic expressions in my posts, please.
NextPermutation
from the packageCombinatorica
. However, this could take a long tome. $\endgroup$g
s (g1
,,g2
,g3
,g4
,g5
) as a singleG
(sinceg
s need to stay together). Then 9 objects (G
andb1
,b2
,..,b8
) can be arranged in 9! ways, and, for each of 9! permutations,G
can be arranged in5!
ways. Hence the answer 9! 5!. $\endgroup$