You are given access to an interactive server that holds a secret 4-digit code. Your goal is to figure out this hidden number. The code is made up of digits from '0' to '9', and leading zeros are allowed.
To interact with the server, you use a predefined class called GuessServer. It provides a method guessNumber that takes your 4-digit string guess and returns how many digits match both in value and position.
class GuessServer {
...
public int guessNumber(String guess) { ... }
}
For instance, if the secret is "1211":
guessNumber("1214") gives 3, because the first, second, and third digits ("1", "2", "1") are exactly right.guessNumber("9999") gives 0, since none of the digits match.Your job is to write a function that discovers the secret by calling guessNumber repeatedly, aiming to use as few guesses as possible.
Constraints:
'0' to '9'.Example
secret = "1234" (not known to your function)
"1234"
Your function should return the exact secret after making as few calls as possible.