Sure! Here's my solution in Python 3:

T = int(input())
COR = 'CORRECT'
SMALL = 'TOO_SMALL'
BIG = 'TOO_BIG'

for qw in range(1, T+1):
a, b = map(int, input().split())
n = int(input())
while True:
mid = (a + b + 1) // 2
print(mid, flush=True)
result = input().strip()
if result == COR:
break
elif result == SMALL:
a = mid
else:
b = mid - 1


On Fri, Apr 6, 2018 at 1:15 PM Yu Wang <parukia...@gmail.com> wrote:

> Hi,
>
> Could anyone post a working solution for the interactive problem using
> python? I just can't seem to get it to work, and when I use the testing
> script, the script just seems to stop and gives no output (and I can't seem
> to break/keyboard interrupt out of it)
>
> My code is attached below:
>
> import sys
>
> def function(a,b,n):
>     for _ in range(n):
>         guess = (1+a+b)/2
>         sys.stdout.write(str(guess)+'\n')
>         sys.stdout.flush()
>         response = sys.stdin.readline().strip()
>         if response == 'TOO_SMALL':
>             a = guess
>         elif response == 'TOO_BIG':
>             b = guess - 1
>         else:
>             return
>
> cases = int(sys.stdin.readline())
> for case in range(cases):
>     a,b = [int(n) for n in sys.stdin.readline().split()]
>     n = int(sys.stdin.readline())
>     function(a,b,n)
>
>
>
> --
> 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 google-code+unsubscr...@googlegroups.com.
> To post to this group, send email to google-code@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/google-code/dcd7d67a-24f3-4b5a-8110-3633989bb437%40googlegroups.com
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 google-code+unsubscr...@googlegroups.com.
To post to this group, send email to google-code@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/CAHaiWHMxkzkE4cPJWc1UmDLOA8XAN8sPTc-XC02Vd3NJpfoVjw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to