# If you have 3 random numbers between 1 and 27 can guess the fourth?

Problem: Ashley and Ivan want to impress their friends and come up with a magic trick:

One of their classmates comes up with 4 unique random numbers between 1 and 27 and tells them to Ivan. Ivan shares only 3 of the numbers with Ashley and she always guesses the fourth one. No other information is shared between them.

What is the arrangement that Ivan and Ashley have beforehand?

• This is essentially a numerical version of this 5 card trick problem. – Jaap Scherphuis Sep 25 '18 at 8:41
• @JaapScherphuis It seems to be a bit trickier to me, although perhaps I'm missing something. – hexomino Sep 25 '18 at 10:18
• By that, I mean, the surjective map that Ivan and Ashley have to construct has a lot less freedom than in the 5 card trick problem. In fact, it appears to be a bijection. – hexomino Sep 25 '18 at 10:31
• Here is another post about the same card trick. The answer for that question should work for this one as well. – Jaap Scherphuis Sep 25 '18 at 11:34
• A little backstory - I got this question from e 4th grade advanced mathematics book. They shouldn't be familiar multiplication/division – Lirik Vesur Sep 25 '18 at 12:33

## 2 Answers

Since 3 numbers are known to Ashley, the missing 4th can be one of the remaining 24 (since all 4 are unique).

Ivan can name 3 shared numbers in 6 different orders, and can insert the secret one in 4 different position (before 1st, after 1st, after 2nd, after 3rd), so we get 24 different combinations, so, it's a bijection, and Ashley can always guess the secret number.

Example of an arrangement:

Let $$A$$, $$B$$ and $$C$$ be the shared numbers, and they are ordered such $$A. Consider the following table, which can serve as an arrangement:

Sum up the numbers which correspond to the true sentences, and add to the answer the number of shared numbers which are less or equal than that answer.

• order is ABC = 1
• order is ACB = 2
• order is BAC = 3
• order is BCA = 4
• order is CAB = 5
• order is CBA = 6
• missing number on 1st position = 0
• missing number on 2nd position = 6
• missing number on 3rd position = 12
• missing number on 4th position = 18

For example, Ivan can say to Ashley:

The numbers are 8, 16, X, and 5. You must guess the X.

So, Ashley deducts that the order of numbers is $$BCA$$ (since $$5<8<16$$), and the missing number is named on third position. So the answer is $$4+12=16$$. Since all 3 numbers are less or equal than 16, Ashley adds 3 and gets the secret number: 19.

Note: The last step is used to map the 24 numbers from 1 to 24 to the 24 numbers from 1 to 27 except the already named numbers, namely $$\{1,2,...,24\}\to\{1,2,...,27\}\setminus\{A,B,C\}$$

Edit: Since Ivan has the freedom of what number he can remove, he has 4 times more possibilities than there are at first glance. So he can "encode" it without including the unknown number into the message (for example, remove the number based on the sum of all 4 numbers modulo 4 - if they sum to $$4n+1$$, remove the smallest number, $$4n+2$$ - 2nd smallest etc.), reducing the number of possible variation to no more than 6.

• I am skeptical that you would be allowed to place the unknown number in the order like that. – hexomino Sep 25 '18 at 11:09
• @hexomino Why not? The problem only states that one side shares 3 numbers with the other and "hiding" the 4th. For unprepared spectators this phrase may sound natural. – trolley813 Sep 25 '18 at 11:15
• @trolley813 I agree with hexomino, you would not able to say 8,16,X, 5... but 8,16,5... I thought the same methodology but I am pretty sure it would not be possible to do this. – Oray Sep 25 '18 at 11:24
• @trolley813 good idea, but you only get 3 numbers – Lirik Vesur Sep 25 '18 at 11:39
• @LirikVesur Yes, it's actually possible to use the other way for "encoding", I've edited the answer. But, please place a requirement in the puzzle, that Ashley gets from Ivan only 3 numbers and nothing else. – trolley813 Sep 25 '18 at 12:38

Arrangement:

Tell the 3 random numbers A, B and C in a specific order (based on their value) and each number one or two times to communicate a position between 1 and 24, like this: ABC = 1 AABC = 2 ABBC = 3 ABCC = 4 ACB = 5 AACB = 6 ACCB = 7 ACBB = 8 BAC = 9 BBAC = 10 BAAC = 11 BACC = 12 BCA = 13 BBCA = 14 BCCA = 15 BCAA = 16 CAB = 17 CCAB = 18 CAAB = 19 CABB = 20 CBA = 21 CCBA = 22 CBBA = 23 CBAA = 24 When the position between 1 and 24 is known, count forward and jump past the A, B and C numbers to know the actual forth number between 1-27.