Number Guessing Game

I am thinking of a whole number from 1 to 100. What is the fewest number of "yes" or "no" questions you might need to ask me that would guarantee that you can determine my number?

50 99 7 6

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

5 solutions

Eduardo Neo
Sep 14, 2015

By using the Binary Search algorithm, the max. number of steps you would need is

log 2 100 7 \log _{ 2 }{ 100 } \quad \approx \quad 7

This is :

First step : pick the number in the middle of the set {1,2,...100} . In this case, the number is 50. Second step : you ask : "The number I'm looking for is bigger than 50?". If the answer is "yes", then you can reduce your set to {50,51,...100} . If the answer is "no", then your new set is {1,2,...50} .

Now you repeat the until you are left with the one number you're searching!

Nice! This is the same concept as binary search in computer science.

Owen Leong - 5 years, 8 months ago

Log in to reply

Yep, the same Algorithm :D

Eduardo Neo - 5 years, 8 months ago

Well, is the set is 1-50 i can ask 1-50, then 1-25/26-50 then 1-12/13-25 then 1-6/7-12 that is four question. for the next step, if the number is 2, the set should be from 1-3 i'll ask whether the number is from 1-3 or 4-6. that is the fifth question. Finally, i'll ask is the number an even number. which is the only possibility is 2. so six questions are possible. so, if you take some chances, you can arrive in conclusion sooner (only by 6 questions) for some numbers.

Nice Question though!

Tommy Young - 5 years, 9 months ago

Log in to reply

Well, the question is to guarantee it, right? So I think we should consider the worst case possible.

If we leave it to chance, it would also be possible to conclude it in 1 question, like: "Is your number 100?" In this case, there's 1% chance we would have done it in 1 question, but I guess this is not what the author wants.

Just saying~

Calvin Tjahjadi - 5 years, 9 months ago

Yes, true!

Kamlesh Tiwari - 5 years, 9 months ago

This can be done in as little as 6 questions:

Is it above or below 50?

Is it an odd or even number?

Is it a 2 digit number?

Is it above or below 5?

Is it 2?

Is it 4?

Obviously it won't always pan out this way, but it can be done.

Oliver Duce - 5 years, 9 months ago

Log in to reply

Your first question is not a yes/no question, or rather it is but it gives no useful answer. If I said yes, you wouldn't know if I said yes to it being above 50 or yes to it being below 50.

A Former Brilliant Member - 5 years, 9 months ago

The idea of the question is that with 7 questions it always can be figured out. I might say: is it 7? and boom i get it in 1 question, but no always

Michael Laposata - 5 years, 9 months ago

I did it in 5 questions, it says fewest number thus asking if the number is prime and the answer being yes shortens this list from 7 to 5...

Chris White - 5 years, 9 months ago
Otto Bretscher
Sep 15, 2015

My approach is analogous to Eduardo's: Write the mystery number in base 2. Now ask: Is the last digit a 1? Is the second to last digit a 1?...Is the 7th to last digit a 1? With this approach, the questions are independent of the previous answers.

Awesome solution!

Eduardo Neo - 5 years, 9 months ago
Harsh Bhardwaj
Sep 14, 2015

Binary search and log base 2 of 100(ceiling).

Derek Burden
Sep 14, 2015

Ask a series of questions that keeps dividing the numberline search region in half until search narrows in on the number. Is the number less than or equal to 50? Is the number less than or equal to 25? And so on.... 7 questions is all that's necessary.

Yuning Sun
Sep 15, 2015

above/below 50, above/below 25, above/below 12, or increasing if higher, decrease if lower... keep going. should total 7

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...