And now for some solutions to the chessboard counting challenges.

- The first challenge was to count the number of squares of
*any* size on an 8×8 chessboard. The key here (as with many counting problems) is to break the problem down in an appropriate way. In this case, we can think about counting each size square separately. There is only one square with sides of length 8. There are 4 squares of size 7—they can be in one of two positions horizontally, and one of two positions vertically. It’s not hard to see that there are squares of size 6, of size 5, and so on. So the total number of squares is .
- This pattern continues; on an n by n chessboard, there are total squares. There’s actually a nice closed formula for this sum for general
*n*: . (Showing how to derive this formula is a good subject for another post. We can check it for n = 8: , as expected.)
- Counting rectangles instead of squares turns out not to be too much harder. There are 1 by 1 rectangles, 1 by 2 rectangles, 2 by 1 rectangles, and so on. In general, there are j by k rectangles. So the total number of rectangles is
That looks annoying to add up, but there’s a clever trick we can pull. Notice that we can factor an 8 out of the first parenthesized expression above, a 7 out of the second, and so on, yielding

But now we can factor out of this, yielding

Ah, that’s much nicer!

- For a general m by n chessboard, the same method yields
total rectangles. Using the closed formula for the sum of the numbers from 1 through n, we can rewrite this as .

See the comments to the previous post for some further analysis. Also in the comments, Veky posed the following follow-up challenge: how many squares (or rectangles) are there if we also allow squares (rectangles) which are not parallel to the sides of the chess board—the only restriction is that their vertices must occur at “crosshair” points in between the squares of the chess board?

### Like this:

Like Loading...

*Related*

##
About Brent

Associate Professor of Computer Science at Hendrix College. Functional programmer, mathematician, teacher, pianist, follower of Jesus.

For the number of rectangles, consider each rectangle to be formed by two horizontal and two vertical gridlines. Then we have C(9,2) horizontal choices by C(9,2) vertical. Far more elegant.

Aha! You’re right, that is far more elegant. It also amounts to a combinatorial argument why (1 + 2 + … + n) = C(n+1,2).