#include "combo.h"
#include <bits/stdc++.h>
using namespace std;
char get_f_l()
{
char a, b, c, d;
a = 'A';
b = 'B';
c = 'X';
d = 'Y';
if (press({ a, b })) {
if (press({ a }))
return a;
else
return b;
} else {
if (press({ c }))
return c;
else
return d;
}
}
void assign_chars(char f, char& a, char& b, char& c)
{
string s = "ABXY";
int d = 0;
while (f != s[d])
d++;
string r = "";
for (int i = 0; i < 4; i++) {
if (i == d)
continue;
r.push_back(s[i]);
}
a = r[0];
b = r[1];
c = r[2];
}
string gen_q(string s, char a, char b, int n)
{
if (s.size() == n - 1) {
return s + a + s + b;
}
vector<string> qs = {
{ a, a }, { a, b }, { b, a }, { b, b }
};
string res = "";
for (int i = 0; i < qs.size(); i++)
res += s + qs[i];
return res;
}
string guess_sequence(int N)
{
//Pseudocode:
char f_l = get_f_l();
string s = "";
s.push_back(f_l);
char a, b, c;
assign_chars(f_l, a, b, c);
while (s.size() < N) {
// ask for aa, ab, ba, bb
string q = gen_q(s, a, b, N);
int r = press(q) - s.size();
//If r == 0, we know c is the answer;
if (r == 0)
s.push_back(c);
//If r == 1, we know either a or b are the answer in this round, and that c is the answer in the next one;
if (r == 1) {
if (press(s + a) - s.size())
s.push_back(a);
else
s.push_back(b);
s.push_back(c);
}
//If r == 2, we know a or b are the answer in this and in the next round;
if (r == 2) {
if (press(s + a) - s.size())
s.push_back(a);
else
s.push_back(b);
if (press(s + a) - s.size())
s.push_back(a);
else
s.push_back(b);
}
}
s.resize(N);
return s;
}