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$

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.

• Simplify the problem: A two digit number minus a one digit number equals $33$. What do you notice? Then move on to three digit minus two digit and so on. What are your thoughts on this? Mar 25 '20 at 4:51
• A quick Google search returns this reddit post from 6 years ago; it contains two answers but no solution. Mar 25 '20 at 4:53
• @AndrewChin For simpler problem like A two digit number minus a one digit number equals 33, what digits can I use? Mar 25 '20 at 5:16
• Note that these are digits, not numbers. Also, an individual $A_i$ cannot be pairwise distinct; it is the $A_i$ in the plural that are pairwise distinct. Mar 25 '20 at 6:50
• @joriki I edited my question, Is it okay now? Mar 25 '20 at 6:52

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.)

• I do not fully understand the first paragraph. Why would the sum of digits from $1$ to $9$ contribute to the parity of the digit sum of the result? Mar 25 '20 at 12:15
• If you ignore borrowing for the time being, the digit sum of the result is a sum of the digits from $1$ to $9$, each with either a $+$ or a $-$. The sign makes no difference; in either case an odd digit contributes $1$ to the parity and an even digit contributes $0$. Mar 25 '20 at 12:19
• Can you eplain 'Thus the difference between the digit sums of the rows must be $5\cdot3-2\cdot9=-3$'. Where do we get $5\cdot3$ and $2\cdot9$? Mar 27 '20 at 7:02
• @Idonknow: There are five $3$s in the result, so the digit sum of the result is $5\cdot3$. If there were no borrowing, the digit sum of the result would be the difference of the digit sums of the rows. Each borrowing subtracts $1$ from the higher digit and adds $10$ to the lower digit, so the net effect is to add $9$ per borrowing. We found that there are exactly two borrowings. Thus the digit sum of the result is $2\cdot9$ more than the difference between the digit sums of the rows. Mar 27 '20 at 7:06