Generalizing the “Find the missing digit trick” !

In this entry, I shall generalize a very interesting math trick.

Background

A fun and intriguing math performing trick is the “find the missing digit” trick. The mathemagician asks you to think of a number N preferably long, 5 or 6 digits. He will not know this number. He asks you to subtract from it, the sum of the digits of N. He then asks you to call out ALL EXCEPT ONE of the digits of the answer that you got in the previous step and IN ANY ORDER. He will tell you the digit that you didn’t call out.

Example

Lets say audience chooses N= 264983. They subtract 2+6+4+9+8+3 = 32 from 264983. So they will end up with 264983- 32 = 264951. They call out… 2..9..4..6..5 and leave out 1. The mathemagician will have 2+9+4+6+5 = 26 in his hand and the next multiple of 9 is 27. So he will know that the audience left out 1.

The logic behind this trick is that subtracting the sum of digits from a number leaves the number as a multiple of 9.

Why we try to make this a multiple of 9 is because the sum of digits of a multiple of 9 is also a multiple of 9. Which means that if the mathemagician has 5 of the 6 digits, he can simply check which digit would make the sum of the digits a multiple of 9.

Generalization

The problem with the above method is that you need the number to be a multiple of 9 which makes this trick very specialized and the problem with most magic tricks is that once you’ve seen them enough times, they lose their charm. By attempting to generalize this particular trick, one can open the doors to whole new set of tricks. My goal is to find the missing digit when it is a multiple of not just 9, but any number like 4 or 7 or 3. For this we need to know the basics of number theory.

Let us take a start with a $n$ digit number $N$ that needs to be divisible by a number $p$. I shall define a set of base values S = { $a_1, a_2 ..., a_n$} where $a_1=1, a_2 = 10^{2-1}(modp), a_3 = 10^{3-1}(modp)... a_n = 10^{n-1}(modp)$

The following table shows the base numbers for 4 digit numbers for various $p$

p Base Numbers
7 6,2,3,1
17 -3,-2,10,1
31 8,7,10,1

The principle will remain the same as before. In order to find the missing digit, the number of the audience $N$ should be a multiple of $p$ of our choosing. We shall use the base numbers $S$ corresponding to $p$.

Once we have $N$ and $p$, we’re almost good to go. Here is the caveat. You cannot allow the audience to scramble the digits and they have to tell you which position’s digit they omit.

Perform the following algorithm:

Step 1: Multiply the digits of the number $N$ with its corresponding base numbers. For instance, multiply the first digit by $a_1$, the second digit by $a_2$ .. and the $nth$ digit by $a_n$

Step 2: Add them all up. The sum will be a multiple of $p$.

Step 3: We check which is the nearest next or previous multiple of $p$ and figure out the missing digit either by quick observation or by using the euclidean algorithm

Much Needed Example:
Number: 6258 (multiple of 7). This you would make the audience end up with using some simple ‘mathemagic’ manipulations.

So you ask them to omit the 3rd digit from the right and say the rest. So they will say 6..5..8.

Step 1: Look up the table. The base digits for p=7 are 6, 2, 3 and 1. You will do $6 \times 6 + x \times 2 + 5 \times 3 + 8 \times 1$ inside your head, where $x$ is the missing digit.

Step 2: This equals $59+ (2 \times x)$

Step 3: we know that $59+ (2 \times x)$ is a multiple of 7. What is the next (since we’re adding to 59)nearest multiple of 7? 63! so $59+ (2 \times x) = 63$ and that gives us the missing number 2 !

Another Example!

Number: 1632 (multiple of 17).

So you ask them to omit the 3rd digit from the right and say the rest. So they will say 1..3..2

Step 1: Look up the table. The base digits for p=7 are -3, -2, 10 and 1. You will do $-3 \times 1 + x \times -2 + 10 \times 3 + 2 \times 1$ inside your head.

Step 2: This equals $29- (2 \times x)$

Step 3: we know that $29- (2 \times x)$ is a multiple of 7. What is the previous (since we’re subtracting from 29) nearest multiple of 7? 17! so $29- (2 \times x) = 17$ and that gives us the missing number 6

You will notice that the answers are pretty obvious here. That is because the base number of the corresponding missing digit is 2 which is a low number and is easy to calculate in your head. In cases where the base number of the missing digit is a large number, then the Euclidean algorithm would need to be used which I shall cover in another post.