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?
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.
Nice! This is the same concept as binary search in computer science.
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!
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~
Yes, true!
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.
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.
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
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...
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!
Binary search and log base 2 of 100(ceiling).
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.
above/below 50, above/below 25, above/below 12, or increasing if higher, decrease if lower... keep going. should total 7
Problem Loading...
Note Loading...
Set Loading...
By using the Binary Search algorithm, the max. number of steps you would need is
lo g 2 1 0 0 ≈ 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!