We are going to play a regular “find my number” game, i.e. you announce your initial guess and following my answer ( limited to: “more “, “less” or “right!”) go on to your next guess.
Usually to reveal a number from 1 to N you need no more than log
2N guesses
in the worst case.
How many guesses are needed if I told you that my number
is a 4-digit palindrome divisible by 7 ?
Assume the worst case, of course.
ct=0;
for a=10:99
n=char(string(a));
n=str2double([n flip(n)]);
if mod(n,7)==0
disp(n)
ct=ct+1;
end
end
ct
log(ct)/log(2)
finds 18, whose base-2 log is 4 and a fraction.
1001
1771
2002
2772
3003
3773
4004
4774
5005
5775
6006
6776
7007
7777
8008
8778
9009
9779
ct =
18
ans =
4.16992500144231
By the example given in the puzzle, what's sought is the number of guesses needed to determine the hidden number, rather than that necessary to actually make that number the guess. That being the case, the answer is 4 guesses.
In either game, it may actually take one more guess in order actually make the guess "official". In the original version, say, Guess a number between 1 and 4. The base 2 log of 4 is 2. Suppose the number is 4. The first two guesses are: 2 and 3 so by this time the number is known to be 4, but it's not yet guessed, so it actually takes 3 guesses to get the actual number to be a guess.
The same works here: worst case the number is 9779 and the guesses are 5005, 7007, 8008, 9009. It's now known that the number is 9779, but it takes a fifth guess to nail down the "got it".
|
Posted by Charlie
on 2023-05-15 08:02:01 |