Datasets:

ArXiv:
License:
File size: 1,510 Bytes
c574d3a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package torea;

class GuessTheNumber
{

    public static class Guesser{
        public int max;
        public int min;
        public int mid;

        Guesser(int amin, int amax){
            min = amin;
            max = amax;
            setMid();
        }

        public String makeGuess()
        {
            return Integer.toString(mid);
        }

        public void toHigh()
        {
            max = mid;
            setMid();
        }

        public void toLow()
        {
            min = mid;
            setMid();
        }

        public void correctGuess()
        {
            min = mid;
            max = mid;
        }


        public void setMid(){
            mid = (max-min)/2+min;
        }

        public Boolean decided(){
            return max == min;
        }
    }
    public static void main(String[] args){
        Kattio io = new Kattio(System.in, System.out);

        Guesser guesser = new Guesser(1, 1001);

        while(!guesser.decided()){
            io.println(guesser.makeGuess());
            io.flush();
            
            String response = io.getWord();
            if(response.equals("correct")){
                break;
            }
            else if (response.equals("lower")){
                guesser.toHigh();
            }
            else if (response.equals("higher")){
                guesser.toLow();
            }
        }
        
        io.close();
    }
}