import std.stdio; import std.conv; import std.array; import std.algorithm; import core.bitop; import core.stdc.stdlib; void main() { detectSequence(detectCombination()); } ushort detectCombination() { ushort[] candidates = generatePermutation(); while (0 < candidates.length) { ushort q = candidates.back; candidates.popBack; query(decode(q)); ushort[][] grouped = group(q, candidates); int n = reply(); if (4 == n) return q; candidates = grouped[n].dup; } return 0; // dummy; } ushort[] generatePermutation() { ushort[] perm; foreach (i; 0..10) { foreach (j; 0..10) { if (j == i) continue; foreach (k; 0..10) { if (k == i || k == j) continue; foreach (l; 0..10) { if (l == i || l == j || l == k) continue; perm ~= encode([i, j, k, l]); } } } } return perm; } ushort encode(int[] n) { return to!ushort((1<