# Sunday Times Teaser 2556 – Dotty Squares

*by Andrew Skidmore*

#### Published: 18 September 2011 (link)

On a piece of paper I have drawn a neat, evenly spaced square array of 36 dots, namely six rows of six.

If I were to ask you how many squares are formed, you might say just 25, for the array seems to consist of 25 little squares. However, lots of sets of four of the dots form the vertices of a square.

How many ways are there of choosing four of the dots so that they form the vertices of a square?

One Comment
Leave one →

This is an interesting teaser as it is easy to miss the fact that there are squares whose sides are not parallel to the sides of the grid. After some effort it is possible to work out that the total number of squares for a grid of \(n\) by \(n\) dots is given by \(n^2(n^2-1)/12\), which generates the sequence 0, 1, 6, 20, 50, 105, 196, … as given here in the The On-Line Encyclopedia of Integer Sequences (the count for rectangles rather than squares is given here). When this teaser was first published, I wrote one of my first Python programs to count the number of squares and rectangles in a square grid of dots. I have just dug it out and improved it a bit so here it is: