An Obvious Interactive Problem

I pick a number. You guess it. You can guess at most 25 times. For every guess you make, I will tell…

Click here to read the complete problem statement.


If you need help solving this problem, mention your approach and ask specific questions. Please avoid sharing your code and asking the Community to figure out “what’s wrong”.

Is this possible to solve this with Python 3.7. I can’t find any other way. Here is my code:

import random
x = 1000000
y = 0
for i in range(25):
	a = random.randint(y, x)
	print(a)
	b = input()
	if b == "Bigger":
		y = a+1
	elif b == "Smaller":
		x = a
	elif b == "Bingo!":
		break
	else:
		break

@Abdullah_1234, yes it is absolutely possible to solve this problem with python.
Toph already has a tutorial about it !!!
However, it might have been removed so I cannot find it.
Any clue, @hjr265 ?

I found two errors in your code.

  1. You are using a random number. You can’t use random number because it gives random number
    every time. You need to use binary search. You just need to replace
    a = random.randint(y, x) with
    a = int((x + y) / 2)
  2. Your’re using wrong qutations
    The one you used “ ”
    But it should be " "
    if you fix these you will get an Accepted verdict.
    Here is the AC code: [REDACTED]
1 Like

He wasn’t actually using wrong quotations.
It happens when you write something in the community.
The quotations are changed.

is it possible to with C? I tried binary search. Still shows CLE. Even though I managed to avoid strcmp() function. Any tips?

What’s wrong in my code?Showing CLE. Please check and help me.

#include <stdio.h>
#include<string.h>
int main()
{
    int a, l=0, h=1000000, i=0, p=0, j;
    p=(l+h)/2;
    for(i=0; i<25; i++)
    {
        char str[20];

        printf("%d\n", p);
        scanf("%s", str);
        if((h-l)<=5)
        {
            for(j=l; j<=h; j++)
            {
                printf("%d\n", j);
                scanf("%s", str);
                if(strcmp(str, "Bingo!")==0)
                {
                    break;
                }
                else
                {
                    continue;
                }
            }
        }
        else if(strcmp(str, "Bingo!")==0)
        {
            break;
        }
        else if(strcmp(str, "Smaller")==0)
        {
            h=p+1;
            p=(l+p)/2;
        }
        else if(strcmp(str, "Bigger")==0)
        {
            l=p;
            p=(h+p)/2;
        }
    }
    return 0;
}

the problem is in Binary search section!
you can’t just use random

I didn’t know about binary search before I started this problem that’s why I posted a silly question. I got AC after solving this problem with binary search🙂.

fflush(stdout) is required, or CPU limit exceeded will be shown in C

why it says “CPU limit exceeded on test 1” when i run this??

i=0
while i<26 :
i=i+1
a=input()
b=int(a)
x=3
if x>b :
print(“Bigger”)
elif x<b :
print(“Smaller”)
else :
print(“Bingo”)
break