Analysis of how-many-squares and rectangles are are there on a chess board?

Solution 1:

Here is an easy way to count the number of rectangles. There are $9$ horizontal lines on the chessboard, and $9$ vertical lines. Choose two distinct horizontal lines, and two distinct vertical lines. These determine a unique rectangle. And any rectangle determines a pair of horizontal lines and a pair of vertical lines.

So the number of rectangles is $\binom{9}{2}^2$. That is $1296$.

Exactly the same idea can be used to count the number of rectangles on an $m$ by $n$ chessboard. It is $$\binom{m+1}{2}\binom{n+1}{2}.$$

The number of squares is a bit less nice. It is easy to see that there are $8^2$ small $1\times 1$ squares, $7^2$ $2\times 2$ squares, and so on down to $1^2$ $1\times 1$ squares, for a total of $$1^2+2^2+3^2+\cdots+8^2.$$ Now we can add up, but there is also a simple formula for the sum of the first $n$ squares. The same idea works for counting the squares on an $n \times n$ chessboard.

Solution 2:

If you look at a chessboard ($n = 8$), there are

  • 1 square of size 8x8
  • 4 squares of size 7x7
  • 9 squares of size 6x6
  • and so on until
  • 64 squares of size 1x1

So, really, the formula boils down the the summation $\sum_{i=1}^n i^2$, which can be derived as shown in the answers here. See also a combinatorial approach to better suit your question.

For rectangles, note that for an $n \times m$ chessboard, there are $n+1$ lines that form the rows and $m+1$ lines that form the columns. A rectangle will be bound by two of these rows and two of these columns, so the number of rectangles is given by:

$R(n,m) = \binom{n+1}{2}\binom{m+1}{2}$

Note that the formula is generalized for any rectangular chessboard, not just a square one.

Solution 3:

To get the squares, integrate $(m+1-x)(n+1-x)$ for $x$ from $1$ to $m$, where $m$ and $n$ are the dimensions of a $m\times n$ chessboard, where $m\lt n$.