Few months away from my little blog, I decide to make the “I am back post” by going through an interesting brain teaser again.

Months ago, one of my closest friends sent a little quiz in our chat group. I was immediately attracted by the quiz and started to think about it. Then I realized it is not an easy problem. I opened the terminal and wrote a few lines of Python to help me to do the calculation. Things got more interesting when I started to code. Finally I spend some time get the answer. It is so fun to work on such a beautiful math problem.

### Problem

There are two different numbers in range of 2-99. One mathematician (Mr. P) knows the product of the two numbers, and the other mathematician (Mr. S) knows the sum of the two numbers, they have the following conversations:

Mr. P: I don’t know what x, y are Mr. S: I knew you don’t know! Mr. P: Now I know! Mr. S: well, I will know if you know.

So, what are the two numbers?

### My mind map to solve it

#### We know a lot from unknown

Mr. P: I don’t know what x, y are. Mr. S: I knew you don’t know!

There are some information hidden in the first around of conversation between Mr. P and Mr. S

At least one of the numbers is not prime.

- If both the numbers are prime numbers, Mr. P who knows the product can easily do the factorization and get the numbers
We can get a list of possible sums of the two numbers, which are the sums of any two numbers (5-197) exclusive of the sums of two prime numbers

- That is why Mr. S could say that he “knew!” because he is sure that what he got in hand - the sum of the two numbers - is definitely not a sum of two primes.

So we can get a list of possible sums p :

There are 83 possible sums. What Mr. S has in hand must be one of the numbers. Still quite a large range, but we get the possible list p that we can continue to work on.

#### Get it done with brute force

Mr. P: Now I know!

Suppose that the smart mathematician Mr. P also comes up with the previous analysis, he shall have that list of possible sums p in hand as well. If he now factorizes the product he got in hand into two numbers between 2-99, he could get a few different pairs, then a few sums from these pairs.

one and only one from the factor pairs, gives a sum in the possible sums list p shown above

- This is what makes Mr. P be so sure about the unique answer

Now we can list all the possible products of two numbers between 2-99, then do brute-force search among all using this logic.

Helper function I - Find the factors of a number:

Helper function II - Find the list of sums from its factor pairs of a number:

Helper function III - Base on the logic, check if one and only one sum in sum list for a number is in the possible sum list p:

Now do the brute-force search among all the products of two numbers between 2-99

This is a long list which contains 678 possible pairs. We know the answer must be in this list li.

#### The hidden special one

Mr. S: well, I will know if you know.

Among such a long list li, how could we identify the particular result? Here is a special case:

the sum that only appears once in the list.

- Only in this case, Mr. S could find a unique pair of numbers corresponding to the sum, otherwise ambiguity remains.

Let’s count the occurrence of sums of the 678 possible pairs in list li and print it out

In the list, (17, 0) is the only one with 1 occurance. This is excatly what we are looking for. Look back in list li we find (17, 4, 13). These two numbers are 4 and 13!

Some more information about this quiz can be found online. The Impossible Puzzle, also named Sum and Product Puzzle is a puzzle called “impossible” because it seems to lack sufficient information for a solution. It was first published in 1969 by Hans Freudenthal, and the name Impossible Puzzle was coined by Martin Gardner. The puzzle is solvable, though not easily.

I feel good about straight forward logic but start to get headache when math comes in the way :( Maybe this is the reason I could not survive in Acedamia. Anyway, I am back to my little blog and feel really good.