2
$\begingroup$

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?

$\endgroup$
3
  • $\begingroup$ Wrong site - you most likely want math.stackexchange.com. $\endgroup$
    – Yves Klett
    Commented Jun 21, 2014 at 17:08
  • $\begingroup$ This question appears to be off-topic because it is about a homework question that has nothing to do with Mathematica. $\endgroup$ Commented Jun 21, 2014 at 17:17
  • 2
    $\begingroup$ I have edited this question to make it acceptable to this site. I did so because I would like it to be reopened. I think Bob Hanlon's answer is worth preserving. $\endgroup$
    – m_goldberg
    Commented Jun 21, 2014 at 22:19

2 Answers 2

2
$\begingroup$

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):

tu = Tuples[Table[{Yellow, Blue, Green, Red}, {6}]];
dtu = DeleteCases[tu, {___, x_, x_, ___}];
Length@dtu 

yields 972. (as has been pointed out by eldo this is essentially as per Bob Hanlon)

The flags can be visualized:

flag[u_] := 
 Graphics[MapThread[{#1, Rectangle[{#2, 0}, {#2 + 1, 4}]} &, {u, 
    Range[6]}]];
GraphicsGrid[Partition[flag /@ dtu, 27], Frame -> All, 
 ImageSize -> 800]

enter image description here

$\endgroup$
4
  • 2
    $\begingroup$ Where is the difference to Bob Hanlon's answer (except that you show more flags) ? $\endgroup$
    – eldo
    Commented Jun 23, 2014 at 11:27
  • $\begingroup$ @eldo I agree eldo, in retrospect, that I should have read BobHanlon's answer properly and apologize. One minor point of difference is operational...by using the "colors" it facilitates visualization. I am sorry. If you wish I can delete or perhaps more appropriately attribute to Bob Hanlon. $\endgroup$
    – ubpdqn
    Commented Jun 23, 2014 at 11:49
  • $\begingroup$ I would write something like: "Based upon BH's answer ..." :) $\endgroup$
    – eldo
    Commented Jun 23, 2014 at 11:57
  • $\begingroup$ @eldo thank you eldo I have edited to answer (as well as appropriately upvoting Bob Hanlons) $\endgroup$
    – ubpdqn
    Commented Jun 23, 2014 at 11:59
8
$\begingroup$

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.

4*3*3*3*3*3

972

Alternate approach

colors = {yellow, blue, green, red} // Sort;

(flags1 = DeleteCases[Tuples[colors, {6}], {___, x_, x_, ___}]) // Length

972

toColors = Thread[colors -> {Blue, Green, Red, Yellow}];

Examples from flags1

Partition[
  Graphics[Thread[{flags1[[#]] /. toColors, 
       Table[Rectangle[{n - 1, 0}, {n, 6/GoldenRatio}], {n, 6}]}], 
     ImageSize -> 100] & /@ Range[9], 3] // Grid

enter image description here

If all four colors must be used

(flags2 = Select[flags1, Union[#] == colors &]) // Length

600

Examples from flags2

Partition[
  Graphics[Thread[{flags2[[#]] /. toColors, 
       Table[Rectangle[{n - 1, 0}, {n, 6/GoldenRatio}], {n, 6}]}], 
     ImageSize -> 100] & /@ Range[9], 3] // Grid

enter image description here

$\endgroup$
8
  • $\begingroup$ I think it should be mentioned that sorting the list of colors is only necessary for finding flags2. $\endgroup$
    – m_goldberg
    Commented Jun 21, 2014 at 22:09
  • $\begingroup$ I still don't see any flag though. I want the flag! :p $\endgroup$
    – Öskå
    Commented Jun 21, 2014 at 22:28
  • $\begingroup$ Sample flags added. $\endgroup$
    – Bob Hanlon
    Commented Jun 22, 2014 at 5:55
  • 1
    $\begingroup$ I feel compelled to point out that the OP asked for vertical stripes. $\endgroup$
    – m_goldberg
    Commented Jun 22, 2014 at 8:52
  • 3
    $\begingroup$ @m_goldberg try setting your $HeadOrientationRelativeToScreen variable to -π/2 :) $\endgroup$
    – gpap
    Commented Jun 22, 2014 at 11:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.