The number of ways of colouring an m by n grid one of two colours without restriction is . The following examples show what happens when varying restrictions are placed on the colouring.

**Example 1**: The number of ways of colouring an m by n grid black or white so that there is an even number of 1s in each row and column is

**Proof**: The first rows and columns may be coloured arbitarily. This then uniquely determines how the bottom row and rightmost column are coloured (restoring even parity). The bottom right square will be black if and only if the number of black squares in the remainder of the grid is odd, hence this is also uniquely determined by the first rows and columns. Details are also given here.

**Example 2**: The number of ways of colouring an m by n grid black or white so that every 2 by 2 square has an odd number (1 or 3) of black squares is

**Proof**: First colour the first row and first column arbitarily (there are such squares each with 2 possibilities). This uniquely determines how the rest of the grid must be coloured by considering the colouring of adjacent squares above and to the left.

By the same argument, the above is the same as the number of colouring an m by n grid black or white so that every 2 by 2 square has an even number (0, 2 or 4) of black squares.

**Example 3**: The number of ways of colouring an m by n grid black or white so that every 2 by 2 square has two of each type is

**Proof**: If there are two adjacent squares of the same colour with one above the other, the remaining squares of the corresponding two rows are uniquely determined as being the same alternating between black and white. The remainder of the grid is then determined by the colouring of first column ( possibilities where we omit the two cases of alternating colours down the first column). Such a grid cannot have two horizontally adjacent squares of the same colour. By a similar argument a colouring that has two adjacent colours with one left of the other can be done in ways. Finally we have the two additional configurations where there are no adjacent squares of the same colour, which is uniquely determined by the colour of the top left square. Hence in total we have possible colourings.

This question for was in the 2017 Australian Mathematics Competition and the general solution is also discussed here.

**Example 4**: The number of ways of colouring an m by n grid black or white so that each row and each column contain at least one black square is (OEIS A183109)

Proof: First we count the number of colourings where a fixed subset of columns is entirely white and each row has at least one black square. The remaining columns and rows can be coloured in ways. To count colourings where each column has at least one black square we apply the principle of inclusion-exclusion and arrive at the above result.

Another inclusion-exclusion example shown here counts the number of 3 by 3 black/white grids in which there is no 2 by 2 black square. The answer is 417 with more terms for n by n grids in OEIS A139810.

**Example 5**: Suppose we wish to count the number of colourings of an m by n grid in which row i has black squares and column j has black squares (, ). Following [1], the number of ways this can be done is the coefficient of in the polynomial

To see this note that expanding the product gives products of terms of the form where such a term included corresponds to the ‘th row and th column being coloured black. Hence the coefficient of is the number of ways in which the system has a solution (, ) for equal to 1 if and only if row and column are coloured black and 0 otherwise.

Let us evaluate this in the special case of 2 black squares in every row and every column for an n by n square grid (i.e. and ). Picking two squares in each column to colour black means viewing the expansion as a polynomial in the coefficient of has sums of products of terms of the form . Then using notation to denote the coefficient of an expression, we have

Here the second last line follows from considering the number of ways that products of terms of the form arise in the product (which is ) and products of terms of the form can be formed in the product (which is ).

For example, when this is equivalent to finding the coefficient of in . Products are either paired up in complementary ways such as in ( ways) or we have the three products ( ways). This gives us a total of 90 (this question appeared in the 1992 Australian Mathematics Competition). More terms of the sequence are found in OEIS A001499 and the 6 by 4 case (colouring two shaded squares in each row and three in each column in 1860 ways) appeared in the 2007 AIME I (see Solution 7 here).

**Example 6**: If we wish to count the number of grid configurations in which reflections or rotations are considered equivalent, we may make use of Burnside’s lemma that the number of orbits of a group is the average number of points fixed by an element of the group. For example, to find the number of configurations of 2 by 2 grids up to rotational symmetry, we consider the cyclic group . For quarter turns there are configurations fixed (a quadrant determines the colouring of the remainder of the grid) while for half turns there are configurations as one half determines the colouring of the other half. This gives us an answer of

which is part of OEIS A047937. If reflections are also considered equivalent we need to consider the dihedral group and we arrive at the sequence in OEIS A054247.

If we want to count the number of 3 by 3 grids with four black squares up to equivalence, this is equivalent to the number of full noughts and crosses configurations. A nice video by James Grime explaining this is here (the answer is 23).

**Example 7**: The number of ways of colouring an m by n grid black or white so that the regions form 2 by 1 dominoes has the amazing form

For example, the 36 ways of tiling a 4 by 4 grid are given here. A proof of the above formula using the Pfaffian of the adjacency matrix of the corresponding grid graph is given in chapter 10 of [2].

#### References

[1] L. Comtet, Advanced Combinatorics: The Art of Finite and Infinite Expansions (pp 235-6), D. Reidel Publishing Company, 1974.

[2] M. Aigner, A Course in Enumeration, Springer, 2007.

## Leave a Reply