#include "prison.h"
#include <iostream>
#include <vector>
std::vector<std::vector<int>> devise_strategy(int N) {
std::vector<std::vector<int>> results;
for (int x = 0; x <= 28; ++x)
{
results.push_back(std::vector<int>(N+1, 0));
}
// if saw 0, then take A
results[0][0] = 0;
// if saw 0, and bag has i, then put (1, value of bit 0)
for (int i = 1; i <= N; ++i)
results[0][i] = ((i>>12)&1) + 2;
for (int x = 2; x <= 27; ++x)
{
// get the bit value, and the current bit index
int bit = (x&1);
int bit_idx = (x>>1)-1;
results[x][0] = (bit_idx+1)&1;
//printf("%i,%i = %i\n", x, 0, results[x][0]);
for (int i = 1; i <= N; ++i)
{
int cbit = (i >> (12-bit_idx))&1;
if (cbit == bit) // if both of the bits are equal then what?
{
results[x][i] = ((i >> (12-bit_idx-1))&1) + (2*(bit_idx + 2));
}
else if (cbit > bit)
{
if ((bit_idx+1) & 1)
results[x][i] = -1;
else
results[x][i] = -2;
}
else if (cbit < bit)
{
if ((bit_idx+1) & 1)
results[x][i] = -2;
else
results[x][i] = -1;
}
//printf("if detected bit is %i then %i, bit=%i, cbit=%i\n", i, results[x][i], bit, cbit);
}
}
return results;
}