I spent the last hour of this contest trying to figure out what this 
interactive system wants. I know my solution is correct, I just don't get this 
interactive inputs thing and debugging is impossible.

local function inv(a, b)
        local m, c, d = b, 1, 0
        while b ~= 1 do
                a, b, c, d = b%a, a, d - c*math.floor(b/a), c
        end
        return d%m
end
 
function remainder(n, a)
    local prod = 1
    for i = 1, #n do prod = prod*n[i] end
    local sm, p = 0
    for i = 1, #n do
        p = prod / n[i]
        sm = sm + a[i] * inv(p, n[i]) * p
    end
    return sm%prod
end

local T = tonumber(io.read():match("%d+"))
for _ = 1, T do
    local n = {4, 3, 5, 7, 11, 13, 17}
    local a = {}
    for i = 1, #n do
        local row = {}
        for j = 1, 18 do row[j] = n[i] end
        io.flush()
        io.write(table.concat(row, " ").."\n")
        local result = io.read()
        local count = 0
        for v in result:gmatch("%d+") do count = count + v end
        a[i] = count%n[i]
    end
    local gophers = remainder(n, a)
    io.flush()
    io.write(gophers.."\n")
    local verdict = io.read()
end

-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/5823177e-5290-43f2-bdc4-53e18c040348%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to