# Some mathematical magic

The magician will perform some mathematical magic. He asks his guest to secretly pick any two digit number and then perform a number of operations on it.

1. If the number is even, divide by 2, if it is odd subtract 3 and then divide by 2.
2. Multiply by 3.
4. If the number has 3 digits, subtract 102.
5. Multiply by 6.
6. Subtract 21.
7. Compute the sum of the digits and continue with this sum. For example if you have 41, continue computing with 5=4+1. *
8. If the number has only a single digit, multiply by 2.
9. Subtract 5.

At this point, the magician reveals the number the guest arrived at after step 9.

How does this trick work?

Edit: * As noted in the comments, it can happen that you have a negative number at this point. In this case just ignore the minus sign in front. So for example the sum of digits of -16 would be 7.

• What do you do in step 7 if the number is negative? Treat the sum as negative? (This occurs if you begin with 64, 66, 67, or 69.) Nov 3, 2020 at 21:45
• @NickMatteo Nice catch, when setting the problem up, I didn't notice this could be negative. If you just ignore the negative sign, everything works out as expected. Nov 4, 2020 at 9:15

The number chosen is somewhere between $$10$$ and $$99$$.

1. After the first step, we have a number $$n$$ which is between $$4$$ and $$48$$.

2. After the next two steps, we have $$3n+5$$ which is between $$17$$ and $$147$$.

3. After the fourth step, we have either $$3n+5$$ or $$3n-97$$ which is less than $$100$$. Call this new number $$m$$; it is congruent to $$2$$ modulo $$3$$.

4. After the next two steps, we have $$6m-21=3(2m-7)$$, which is an odd number and a multiple of $$9$$ since $$m\equiv2\;(mod\;3)$$.

5. The digit sum of a multiple of $$9$$ is always a multiple of $$9$$, so after the next step we have either $$9$$ or $$18$$ (it can't be as high as $$27$$ since anything less than $$999$$ won't have such a big digit sum).

6. After the 8th step, we have $$18$$ for sure.

$$13$$. Unlucky!
• @Chris I can't put it directly in terms of $n$ since there are two different options for $m$ in terms of $n$, but I added an extra clause to clarify. Nov 6, 2020 at 7:45