# Sunday Times Teaser 3018 – Debased

*by Howard Williams*

#### Published Sunday July 26 2020 (link)

Sarah writes down a four-digit number then multiplies it by four and writes down the resultant five-digit number. She challenges her sister Jenny to identify anything that is special about these numbers. Jenny is up to the challenge as she identifies two things that are special. She sees that as well as both numbers being perfect squares she also recognises that if the five-digit number was treated as being to base 7 it would, if converted to a base 10 number, be the same as the original four- digit number.

What is the four-digit number?

17 Comments
Leave one →

Corrected – see comments below (the upper limit of 100 on the loop was wrongly set much lower)

What an elegant solution!

Thank you for your kind words, John. But, sadly, not so elegant since it was wrong!

If h = 4n² = (2n)² you only need to consider the even values for i (= 2n).

But, it’s the representation of n² in base 7 that has 5 digits, not the representation of (2n)².

Good point Jim, modified accordingly – an even smaller solution space!.

The teaser says “… if the five-digit number was treated as being to base 7 …”.

This surely refers to \(4.n^2\), not \(n^2\)?

No. There is a string of 5 digits. If it is interpreted as a base 10 number

it gives 4n², if it is interpreted as a base 7 number it gives n².

For example if n=94, then n² = 8836 and 4n² = 35344.

If we take the 5 digit string “35344” and interpret it as base 10 we get

35344 (which is 4n²), and if we interpret it as base 7 we get 9097.

Which isn’t n², but it’s not that far off.

At no point do we need to consider the base 7 representation of 35344

(which would be “205021”).

Sorry Jim, I missed your point first time round.

Hi Brian

I do not understand why your range for i is (100, 121) ie checking values of h only up to 14400.

Just considering h as 4 x (a 4 digit square) gives highest possible value 4 x 9801 = 39204 which seems to demand range (100, 199).

Obviously considering base 7 gives max h = 36666 (and so 36100) but this still needs (100, 191).

The maximum 5 digit number in base 7 is \(6.7^4\) which is 14406, less than \(121^2\).

The maximum 5 digit number in base 7 is 66666.

thanks, corrected now.

base 7 conversion (manual method):

5 digit number is a b c d e

converted value = a*2401 + b*343 + c*49 + d*7 + e

Hi Robert

If I knew of a built-in routine for converting from base 7, I would gladly have used it. Because I don’t, my function “to7” (should have been named “from7”) above, uses exactly the manual procedure you describe. To establish 2401, 343, 49, 7, 1, it uses 7^e and lets e loop 0-4 (and sums the terms).

A weakness with my programme though, is perhaps that it does not filter out numbers containing digits larger than six, like Brian’s. (My semi-manual spreadsheet and pencil-solution of course did that.) In my programme I only got it to work through a very clumsy construction that doubled the amount of code. When I discovered that it did not affect the solution, I simply removed it (without analysing if that could be defended for the more general case..)

PS: Reading Brian’s code more thoroughly, I see that the conversion in question can be done by the built-in function number base 10 = “int(number as string, base)”.

Hi Erling

The only reason that I put my manual conversion routine on this page was that the “add files” link had disappeared from my main ST screen. As this happened on the day that Brian altered his white text, I assumed he was responsible, but it seems that Google had decided to log me out, coincidently on the same day. Logging back in, the “add files” section has re-appeared. So hopefully, you will all be able to see John Crabtree’s clever solution when he posts it. There’s no need to continue this discussion, unless you also lost the “add files” link!