[Math] In how many ways can the four walls of a room be painted with three colours so that no two adjacent walls have the same colour

combinationscombinatoricsinclusion-exclusionpermutations

In how many ways can the four walls of a room be painted with three colours so that no two adjacent walls have the same colour ?


I specifically want to use inclusion exclusion principle.
So according to me it should be $$3^4-4\times 3^3+4\times 3^2-3 $$ which is $6$. The correct answer is $18$. Am making a mistake in applying the principle ? I thought like this – Total ways to colour – ways to colour two adjacent walls with same colour + ways to colour three adjacent walls with same colour – ways to colour all four walls with same colour.

Best Answer

If you insist on using the inclusion exclusion principle you can argue as follows:

Denote the vertical edges of the room by $e_i$ $(1\leq i\leq4)$. There are $3^4$ colorings with no restrictions. There are ${4\choose1}\cdot 3^3$ colorings with at least one illegal edge $e_i$, ${4\choose2}\cdot 3^2$ colorings with at least two illegal edges $e_i$, $e_j$, $i<j$, then ${4\choose3}\cdot3^1$ colorings with at least three illegal edges $e_i$, $e_j$, $e_k$, $i<j<k$, and finally ${4\choose4}\cdot 3$ colorings with all four edges certified illegal. The total number of legal colorings then comes to $$3^4-{4\choose1}\cdot 3^3+{4\choose2}\cdot 3^2-{4\choose3}\cdot3^1+{4\choose4}\cdot 3=18\ .$$