### Random Post

### Recent Posts

### Recent Comments

### Archives

### Categories

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

### Site Stats

- 166,224 hits

Programming Enigma Puzzles

9 December 2011

Posted by on **From New Scientist #1152, 26th April 1979** [link]

A “near-square” is a rectangle of

n× (n+1) units, and the problem is to fill it completely with as few “squarelets” — that is, smaller integral-sided squares — as possible. For a 5 × 4 you cannot do better than 5 squarelets, as the figure shows.With how few squarelets can you fill:

(a) an 18 × 19 near-square?

(b) a 22 × 23 near-square?

[enigma10]

Advertisements

%d bloggers like this:

The following Python program works by deconstructing the product of n x m in to as few squares as possible, then tries to fit those squares into an n x m grid.

Runtime (using PyPy) is 1.3s for the 18 x 19 case and 56.9s for the 22 x 23 case.

Solution:(a) An 18 x 19 near-square can be filled with 7 squarelets. (b) A 22 x 23 near-square can be filled with 8 squarelets.I don’t have a Python compiler and am too stupid to work out a back-tracking (and/or recursive) method in Basic. Juggling the squares by hand always seems to need more of them — perhaps I’m too impatient as well. Can anyone provide solutions for those 7 and 8 squarelets respectively?

If you want to try Python it is freely available for many platforms (and installed by default on some). I would recommend it if you want to explore programming beyond BASIC. See http://www.python.org for details.

Here are diagrams of the solutions my program finds for the 18×19 and 22×23 squares:

The smallest “near square” that requires 9 squarelets is 19×20.

That’s great: thanks a lot, Jim.

Oh, and I do appreciate your insights, methods, references to sources, and other comments. It was a great weakness of the Enigmas (enigmata?) that usually all we got was a bald solution — often just a single numerical value — and were none the wiser as to how it was derived. My own sledgehammer or ‘British Museum’ approach was not usually very educational. Some puzzles were later explained on the NS web site, but only a small proportion of the total.