TITLE: A number guessing game
QUESTION [11 upvotes]: Alice chose a positive integer $n$ and Bob tries to guess it.
In every turn, Bob will guess an integer $x$ $(x>0)$:

If $x$ equals $n$, then Alice tells Bob that he found it, and the game ends.
If not, then Alice tells Bob whether $x+n$ is prime or not.

How to play this game optimally (that is to say, to find the number in the fewest turns)?
You can assume $0< n\le100$ (or any reasonable bound).
PS: This game is invented by me.

REPLY [2 votes]: To get a somewhat efficient algorithm, we can first compute for several choices of $x$ what the answers of Alice would be, for each choice of $n$ between $1$ and $100$. 
As noted by Charles, no matter what $x$ is, for at most $26$ of the $100$ possible choices of $n$ will the answer be "Yes, $n + x$ is prime." This maximum information rate is achieved only by choosing $x = 1$, so we will want to ask this question as our first question. There are five choices of $x$ for which there are $25$ numbers where the answer is "Yes", which are $2, 3, 4, 9, 10$. For simplicity, let us assume that we first query the first $4$ numbers with such a high "information rate": 
$$x \in \{1, 2, 3, 4\}.$$
Now, for each choice of $n$, we can compute what the answers would have been. For the numbers $n = 1, 2, 3, 4$ we would get a match and be done, while for the other $96$ numbers there are only $7$ possible sequences of answers. Along with the choices of $n$ that lead to these answers, these sequences are:
$$\begin{align} 
NNNN &: \{23, 24, 31, 32, 47, 48, 53, 54, 61, 62, 73, 74, 83, 84, 89, 90, 91, 92\} \\
NNNY &: \{7, 13, 19, 25, 33, 37, 43, 49, 55, 63, 67, 75, 79, 85, 93, 97\} \\
NNYN &: \{8, 14, 20, 26, 34, 38, 44, 50, 56, 64, 68, 76, 80, 86, 94, 98\} \\
NYNN &: \{5, 11, 17, 21, 29, 35, 41, 45, 51, 59, 65, 71, 77, 81, 87, 95\} \\
YNNN &: \{6, 12, 18, 22, 30, 36, 42, 46, 52, 60, 66, 72, 78, 82, 88, 96\} \\
NYNY &: \{9, 15, 27, 39, 57, 69, 99\} \\
YNYN &: \{10, 16, 28, 40, 58, 70, 100\} \end{align}$$
So with $4$ questions, we narrow down the search space to at most $18$ numbers. For each group, we may be able to choose the follow-up questions such that in total, we may need only about $10$ questions or so, but this will be very complicated. Of course, we could query each of the at most $18$ numbers in each of the groups, for a total of at most $4 + 18 = 22$ questions, but that would obviously not be optimal.
A somewhat simpler strategy would be to ask more questions in the initial stage, such as first querying
$$x \in \{1, 2, 3, 4, 5, 6, 7, 8, 9, 10\}.$$
In this case, there are $48$ possible strings of answers (and $10$ exact matches), and each group contains $3$ or fewer values of $n$ that lead to these answers. So once we know the answers to these $10$ queries, we are able to narrow down the search space to at most $3$ numbers, and with at most $2$ questions we may then be able to determine the correct value of $n$. So this would lead to a worst-case complexity of $10 + 2 = 12$ questions.