OU blog

Personal Blogs

Richard Walker

2178

Visible to anyone in the world
Edited by Richard Walker, Friday 2 January 2026 at 22:29

On Stack Overflow a Python beginner asked for help in writing a program to find a 4-digit number ABCD such when multiplied by 4 it reverses its digits, that is 4 x ABCD is DCBA. The kindly folks on Stack Overflow duly provided some help and the unique answer is 2178: 4 x 2178 is 8712.

This was new to me; although searching on "2178" threw up ~52,000,000 hits, this puzzle must have passed me by, until now.

Seeing the solution made me wonder if it could be generalised. There is quite a wide field of possible variations, but the first I looked was whether there is a find a 5-digit number that reversed itself when you multiply it by 4.

And there is: it's 21978. That looked familiar somehow and then I searched for a 6-digit counterpart. 219978 was the answer.

You can probably spot the pattern: we are just adding 9s in the middle. Will it work however many of them we insert? Yes it will; here's why.

Imagine we are doing a multiplication, 219.. lots of 9s...978 x 4.

You can see that for each 9 in the middle we shall have carried 3 and we do 4x9 = 36, plus the carry is 39, so we put down 9 and carry 3 again. This will continue as long as the digit being multiplied by 4 is a 9. When reach the 1 we will still have a carry of 3, and we do 4x1 = 4 plus the carry is 7, and then finally 4x2 = 8. So we can have as many 9s as we like sandwiched between 21 an 78 and multiplying by 4 will always reverse the number's digits, which is really cool.

Python deals with very long numbers really well, so just for fun

n = int('21'+'9'*200 + '78')

n

219999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999978

4*n

879999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999912

Permalink
Share post