local mfl, mce = math.floor, math.ceil local function ask(tbl) io.write(table.concat(tbl, " ")) io.write("\n") io.flush() local ret = io.read() local hit, blow = ret:match("(%d) (%d)") hit, blow = tonumber(hit), tonumber(blow) return hit, blow end local function combination_get_map(n) local combmap = {} for i = 1, n do combmap[i] = {} local ret = 1 for j = 1, i do ret = mfl(ret * (i + 1 - j) / j) combmap[i][j] = ret end end return combmap end local function combination_get_count(combmap, n, k) if k < 0 then return 0 elseif n < k then return 0 elseif k == 0 then return 1 else return combmap[n][k] end end local function combination_get_array(combmap, n, k, idx) local rem = k local retary = {} for i = 1, n do local useCnt = combination_get_count(combmap, n - i, rem - 1) local unuseCnt = combination_get_count(combmap, n - i, rem) if idx <= useCnt then rem = rem - 1 table.insert(retary, i) else idx = idx - useCnt end end return retary end local cmap = combination_get_map(10) local cand = {} for i = 1, 210 do local ary = combination_get_array(cmap, 10, 4, i) for j = 1, 4 do ary[j] = ary[j] - 1 end local h, b = ask(ary) if h + b == 4 then for j = 1, 4 do cand[j] = ary[j] end break end end local function getpattern(n, patall, idx) local used = {} local retary = {} local div = patall for i = 1, n do used[i] = false end for i = n, 1, -1 do div = mfl(div / i) local v_idx = mfl(idx / div) idx = idx % div local tmp_idx = 0 for j = 1, n do if not used[j] then if tmp_idx == v_idx then table.insert(retary, j) used[j] = true break else tmp_idx = tmp_idx + 1 end end end end return retary end for ip = 0, 23 do local idxary = getpattern(4, 24, ip) local z = {} for j = 1, 4 do z[j] = cand[idxary[j]] end local h, b = ask(z) if h == 4 then break end end