Hey,
the provided often only tests very simple cases, but not edge cases.
Your algorithm does have BAD MISTAKE.
You're reusing "guess" as the new boundary after it turned out to be TOO_SMALL
or TOO_BIG, so are KEEPING a value, that already is wrong.
Lets say the given range of values is 0 to 15 and the value to guess is 15.
1. guess = 7 | response = "TOO_SMALL"
2. guess = 11 | response = "TOO_SMALL"
3. guess = 13 | response = "TOO_SMALL"
4. guess = 14 | response = "TOO_SMALL"
5. guess = 14 | response = "TOO_SMALL"
6. guess = 14 | response = "TOO_SMALL"
^^
||
14 repeatts! since (14 + 15) // 2 = 14
If you get the response TOO_SMALL then have to INCREASE guess by one,
or DECREASE it by one if you got TOO_BIG.
Also keep in mindm that the lower bound (A) is exclusive, so you have to use
A + 1 as lower bound.
The run time error occurs, because your program does not handle a
"WRONG_ASNWER" response.
If you ever get WRONG_ANSWER, which happens because of your incorrect
algorithm, the judge will no longer accept guesses , but you're still sending
guesses , and that is what causes the runtime error.
The most obviuos reason
Am Dienstag, 16. April 2019 17:22:36 UTC+2 schrieb fellowjello:
> Hello,
>
> I have a question for the practice binary search guessing game. I am having
> trouble with the stdout and stdin buffer (getting runtime/time out error). My
> code is below:
>
> import sys
>
> def guessSession(A,B):
> res = "";
> while(res != "CORRECT"):
> if res == "TOO_BIG":
> B = guess
> elif res == "TOO_SMALL":
> A = guess
> guess = (A+B)//2
> print(guess)
> sys.stdout.flush()
> res = input()
>
> numTestCases = int(input())
> for i in range(numTestCases):
> A, B = map(int, input().split())
> maxGuesses = input()
> guessSession(A,B)
>
> After consulting the provided Google Python3 solution and the provided
> judging test code (of which passes when run with my algorithm), I do not know
> what may cause the error.
>
> I appreciate the help very much!
> Fernando
--
You received this message because you are subscribed to the Google Groups
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-code/6bce842b-0414-41fe-a11d-756fa7b35750%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.