Alice knows $x+y$, and Bob knows $x^2+y^2$, for some integers $y\leq x\leq 25$. They alternate "I don't know the numbers" six times; then Bob knows.

93 Views Asked by At

I have this numbers teaser:

There exists 2 integers $x $ & $ y$, such that $x\geq y$.

Alice knows the value of $x+y$, and Bob knows the value of $x^2 + y^2$.

The following conversation happens between Bob and Alice.

Bob: I don't know the numbers

Alice: I don't know the numbers

Bob: I don't know the numbers

Alice: I don't know the numbers

Bob: I don't know the numbers

Alice: I don't know the numbers

Bob: I know the numbers.

What are the values of $x$ and $y$ ?

I have been also told that $x$ and $y$ do not exceed 25 each, and that there is a unique answer to this problem.

Does anyone know how it is solved?


Approach: I did try to solve it as this comment suggested, however i couldn't reach a specific value at the end. (Please note this code was written in iPy)

Here is my code:

from itertools import product
options = [(x,y,x+y,x**2+y**2) for x,y in product(range(1,26),repeat=2) if x >= y]
for i in range(100):
    if i%2==0: #Bob
        j=3
    else: #Alice
        j=2
    op = []
    for o in options:
        if len([k for k in options if k[j]==o[j]])>1:
            op.append(o)
    options = op
    
    display(len(options),i)
    if len(options) <= 1:
        break
display(options,i)
1

There are 1 best solutions below

2
On

Assuming $x$ and $y$ are integers in the range $1$ to $25$... Hint:

  • There are ${25 \choose 2}+25=325$ ways to choose $x$ and $y$ (as a pair). List them all, and for each of them calculate what would be Alice's knowledge ($x+y$) and what would be Bob' knowledge ($x^2+y^2$)
  • Now, because Bob does not know outright the solution, cross out the pairs which have a unique value of $x^2+y^2$
  • Now, because Alice does not know outright the solution (but she knows Bob didn't know it - so she has presumably done the previous step in her mind), we can look at the remaining pairs and cross out those that have a unique value of $x+y$.
  • Now, Bob's done the same, but he still doesn't know the solution, so we can go on and cross out again all the remaining pairs with a unique $x^2+y^2$
  • And so on ... following the conversation between Alice and Bob.
  • Eventually, Bob knows the numbers, so the solution is one of the remaining pairs with unique $x^2+y^2$. Hopefully at that stage there will be only one such pair.

It is a finite (though not exactly small) problem, so instead of doing it by hand, leave it to a computer to comb through those pairs.