What is the best strategy for guessing the number game?

  • Thread starter fisico30
  • Start date
  • Tags
    Game
In summary: Thanks for the input, it helps me think about it.In summary, the computer could either start from 1 and go up until it finds the right number, or it could ask more intelligent questions, like "is the number smaller or larger than 50?".
  • #1
fisico30
374
0
Hello Forum,
I just learned about the "guess the number" game. There are 100 numbers, from 1 to 100 and the computer must ask questions to find the correct number.

The computer could start from 1 and go up until it finds the right number. That would involve a certain number of questions.
Or the computer could ask more intelligent questions, like "is the number smaller or larger than 50", etc...


Most of the codes I have seen don't ask that "is the number smaller or larger than 50?" but simply ask some binary questions that are all similar (is this number smaller or larger than the previously guessed number? etc...)

Why?

thanks
fisico30
 
Technology news on Phys.org
  • #2
Hi fisico30. This game usually uses a simple binary search, in which it always halves the interval in which it currently knows where the solution lies. So the "computer" would typically start with a guess of 50 and then simply require to be told if it was either correct or high or low.

If correct the game stops with a score of "one guess". If it was told 50 was high then it would next guess 25, if told 50 was low then it would next guess 75 and so on. Searching by continually halving the interval is easy to implement and fairly efficient.

BTW. This game is sometimes given as a exercise for students learning an introductory programming course. It's about the simplest example the you can think of that in some sense constitutes an "AI" game.
 
  • #3
Thanks uart,

great help. Ideally, the least number of guesses, questions, to get to the right answer, the better...

What would be a slightly more sophisticated version of this game? Instead of asking questions based on halving the interval in which it currently knows where the solution lies, would could be asked?

thanks
fisico30
 
  • #4
Increase the range, say to 0-1,000, and ask if *any* (not which) digit is correct.
 
  • #5
Thanks, I see.

So, if we get the number 3456, we would ask if any of the digits forming this number are correct...
that still seems far from being able to correctly guess the right number though...

thanks
fisico30
 
  • #6
You know it has to be 3xxx or x4xx or xx5x or xxx6.
 

FAQ: What is the best strategy for guessing the number game?

How does the guessing the number game work?

The guessing the number game is a simple game where a player tries to guess a randomly generated number within a given range. The player can make guesses until they correctly guess the number or run out of guesses. The game typically provides clues such as "higher" or "lower" to help the player narrow down their guesses.

What is the purpose of the guessing the number game?

The purpose of the game is to provide entertainment and challenge for the player. It also helps improve critical thinking and problem-solving skills as the player tries to narrow down the correct number based on the given clues.

How is the random number generated in the guessing the number game?

The random number is typically generated using a random number generator function in the programming language or software being used to create the game. This function generates a random number within a given range and assigns it as the "correct" number for the game.

Can I change the range of numbers in the guessing the number game?

Yes, the range of numbers can be customized depending on the programming of the game. Some games may allow the player to choose their own range, while others may have a predetermined range set by the game creator.

Is there a strategy to increase my chances of winning in the guessing the number game?

While the game is based on chance, there are some strategies that can increase your chances of winning. These include starting with the middle number in the range and using the given clues to narrow down your guesses. Some players also use a process of elimination by keeping track of previous guesses to avoid repeating them.

Similar threads

Replies
11
Views
926
Replies
4
Views
1K
Replies
4
Views
1K
Replies
5
Views
2K
Replies
7
Views
2K
Replies
2
Views
2K
Replies
43
Views
5K
Back
Top