6 #define NUM (1 << BITS)
8 static char state[NUM];
12 calc_answer(int secret, int guess, int *black, int *white)
15 int s0=0, s1=0, g0=0, g1=0;
18 if (!((secret^guess) & (1 << i)))
22 if (secret & (1 << i))
32 w = ((s0 < g0) ? s0 : g0) + ((s1 < g1) ? s1 : g1);
41 int i, j, x, y, best, besti, total, black, white, answer[BITS+1][BITS+1];
55 printf("Final decision: %02x\n", best);
63 bzero(answer, sizeof(answer));
67 calc_answer(i, j, &black, &white);
68 answer[black][white]++;
71 for(x=0; x<=BITS; x++)
72 for(y=0; y<=BITS; y++)
82 printf("Selected %04x, %d of %d\n", best, besti, total);
88 int bl, wh, i, red = 0;
93 calc_answer(i, question, &bl, &wh);
94 if (b != bl || w != wh)
96 // printf("Throwing out %02x (%d,%d) != (%d,%d)\n", i, b, w, bl, wh);
102 printf("Reduced to %d\n", red);
114 int secr, round, maxr=0;
116 for(secr=0; secr<NUM; secr++)
118 printf("SECRET=%02x\n", secr);
119 bzero(state, sizeof(state));
125 calc_answer(secr, question, &b, &w);
126 printf("%d: Answer is %d/%d\n", round, b, w);
133 puts("------------------------------------------");
135 printf("MAX=%d rounds\n", maxr);