# Sunday Times Teaser 3029 – Square Jigsaw

### by Victor Bryant

#### Published Sunday October 11 2020 (link)

I chose a whole number and asked my grandson to cut out all possible rectangles with sides a whole number of centimetres whose area, in square centimetres, did not exceed my number. (So, for example, had my number been 6 he would have cut out rectangles of sizes 1×1, 1×2, 1×3, 1×4, 1×5, 1×6, 2×2 and 2×3.) The total area of all the pieces was a three-figure number of square centimetres.

He then used all the pieces to make, in jigsaw fashion, a set of squares. There were more than two squares and at least two pieces in each square.

What number did I originally choose?

1. This gives possible solutions but doesn’t prove that the squares can actually be constructed.

Here is one of many solutions. 2. Lovely recursive function. I found that it is possible to remove the ‘if’ statement at line eleven by substituting ‘x’ for ‘mns’ in line 13:

yield from sum_sqs(area – x * x, x, mxs, sq + (x,))

The ‘sorted’ in line 18 seems redundant. Relic from an earlier version where all the rectangles were printed out?

How did you do the 29×29 puzzle? Manually or Pythonically? Either way it’s impressive.

• Thanks John,

That is a simplification and it is also possible to avoid calculating area – x * x twice (see my update above). The rectangle sort was useful in debugging but, as you say, it serves no other purpose.

I found the 29×29 square with a program. Fitting shapes inside other shapes comes up a lot so I have a standard bit of code for doing this.

3. Even better!

BTW I won’t be posting my smoke-belching, coal-fired code this week.

4. • 