[Math] A five digit number minus a four digit number equals $33333$. What are the two numbers, if you are only allowed to use the numbers $1-9$

combinatoricspuzzlerecreational-mathematics

Question: A five digit number minus a four digit number equals $33333$. What are the two numbers, if you are only allowed to use the numbers $1-9$ once? More precisely,
\begin{align}
& & A_1 \, A_2 \, A_3 \, A_4 \, A_5 \\
& – & A_6 \, A_7 \, A_8 \, A_9 \\
& & \hline 3\,\,\,\,\,3 \,\,\,\,\,3 \,\,\,\,\,\,3 \,\,\,\,\,\,3\\
& & \hline
\end{align}

where $A_1,A_2,A_3,A_4,A_5, A_6, A_7, A_8, A_9 \in \{1,2,3,4,5,6,7,8,9\}$ and they form a pairwise distinct set.

For me, I would guess $A_1=3$ or $A_1 = 4.$ But that is all I got.
I am interested to know its thought process.

Best Answer

The sum of the digits $1$ through $9$ is odd. They contribute to the parity of the digit sum of the result no matter which row they’re in. The digit sum of the result is odd. Thus there must be an even number of borrowings.

A column that causes borrowing must have a $7$, $8$ or $9$ in the bottom row, so we cannot have four borrowings.

On the other hand, if there were no borrowing at all, the possible pairs in a column would be $9-6-3$, $8-5-2$ and $7-4-1$, but we can use at most one from each of these three groups.

It follows that there are exactly two borrowings. Thus the difference between the digit sums of the rows must be $5\cdot3-2\cdot9=-3$, and since the sum of all digits is $\frac{9(9+1)}2=45$, the top row must sum to $21$ and the bottom row to $24$.

We need to have exactly two of $7$, $8$ and $9$ in the bottom row to cause the two borrowings.

It can’t be $7$ and $8$ because then $7$ would have to be subtracted from $1$ and $8$ from $2$, so the two borrowing columns would have to be the two lending columns.

If it were $8$ and $9$, that would leave a sum of $7$ for the bottom row, so that could be $3,4$ or $2,5$ or $1,6$. It can’t be $3,4$ because one of those needs to be $A_1$; it can’t be $2,5$ because $5$ would need to be subtracted from $8$ or $9$; and it can’t be $1,6$ because $6$ would need to be subtracted from $9$.

Thus $7$ and $9$ are in the bottom row. That leaves a sum of $8$ for the bottom row, which could be $3,5$ or $2,6$. But it can’t be $2,6$, again because $6$ would need to be subtracted from $9$.

Thus we have $3,5,7,9$ in the bottom row and $1,2,4,6,8$ in the top row. So $4$ must be $A_1$, $7$ must be subtracted from $1$, $9$ from $2$, $3$ from $6$ and $5$ from $8$. Thus the lenders must be $4$ and $1$, so the top row must start $412$. That leaves two possibilities for the order of the last two columns, so there are two solutions:

41286                     41268
-7953         and         -7935
-----                     -----
33333                     33333

The solutions are confirmed by this Java code. (Full disclosure: I initially made a mistake in the proof and wrote the code to find it, so I knew the solution before I completed the proof.)

Related Question