### Random Post

### Recent Posts

### Recent Comments

Jim Randell on Puzzle #52: Bus change | |

Jim Randell on Enigma 967: Prime cubes | |

GeoffR on Enigma 1707: Making progr… | |

Jim Randell on Enigma 1707: Making progr… | |

Jim Randell on Tantalizer 409: Fe, Fi, Fo,… |

### Archives

### Categories

- article (11)
- enigma (1,364)
- misc (4)
- project euler (2)
- puzzle (90)
- puzzle# (47)
- site news (58)
- tantalizer (92)
- teaser (7)

### Site Stats

- 231,894 hits

The following Python program is a constructive approach that counts the number possible squares on the grid. It runs in 44ms.

If you want a fast non-constructive approach it turns out there is a simple formula that generates the required sequence (see OEIS sequence A002415).

Solution:You have drawn 49 dots.Using the formula S(n) = n²(n² – 1)/12, we are looking for the value of n² where S(n) = 4n², so n²(n² – 1) = 48n², or n² – 1 = 48, hence n² = 49.

Here’s a different way of counting the squares:

It turns out that

`nsquares(n, a, b)`

= [(n + 1) – (a + b)]^{2}, so the sequence we are generating is:`S(n) = sum(csum(i`

^{2}for i in range(1, n)))where

`csum()`

is the cumulative sum function from theenigma.pylibrary.And if you crunch the maths you get: S(n) = (n

^{4}– n^{2})/12.Here is my version.