A flag is to be made with six vertical stripes by using colours yellow, blue, green and red in such a way that no two adjacent stripes should have the same colour. In how many ways is this possible? How could I compute this with Mathematica?
As has been calculated by combinatorial considerations there will be 4*3^5 =972 flags. This can be done with Mathematica (as small enough for brute force):
yields 972. (as has been pointed out by eldo this is essentially as per Bob Hanlon)
The flags can be visualized:
EDITED and CORRECTED to vertical stripes
Allowing that fewer than four colors can be used, then the first stripe can be any of the four colors and each subsequent stripe can be any of the three colors other than the last color used.
Examples from flags1
If all four colors must be used
Examples from flags2