### Random Post

### Recent Posts

### Recent Comments

### Archives

### Categories

- article (11)
- enigma (1,123)
- misc (2)
- project euler (2)
- puzzle (31)
- site news (43)
- tantalizer (31)
- teaser (3)

### Site Stats

- 168,353 hits

Programming Enigma Puzzles

11 March 2013

Posted by on **From New Scientist #2613, 21st July 2007**

How many rectangles can be seen in this 4-by-4 grid shown above? In fact there are exactly 100.

I made a much larger square grid with lines dividing it into little squares (a three-figure number of little squares, in fact) and I calculated the number of rectangles which could be seen in this new grid. I then cut the grid along one of the lines in order to make two rectangular pieces and I calculated the number of rectangles visible in each of my two new pieces. The total of these two numbers was exactly two-thirds of the number visible in my original large square grid.

What was the size of my original grid before I cut it?

[enigma1452]

Advertisements

%d bloggers like this:

This Python program counts the number of smaller rectangles in the larger rectangles, by considering the number of top-right corners for any bottom-left corner. It runs in 59ms.

Solution:The original grid was 27 × 27.You can avoid doing the counting by deriving an equation for R(n,m). The sum of integers from 1 to n is T(n), where:

and it follows that:

and the condition we are looking for is:

which simplifies to:

The following Python program finds the solution using this equation in 34ms.