local function split(inputstr, sep)
    if sep == nil then
        sep = "%s"
    end
    local t={} ; local i=1
    for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
        t[i] = str
        i = i + 1
    end
    return t
end

local result        = {}
local matchId       = ARGV[1]
local coinsPos      = split(ARGV[2],  ",")

table.insert(result, ARGV[2])
table.insert(result, #coinsPos)
for index = 1, #coinsPos, 2 do
    redis.call("HSET", "BATTLES:MATCH:{" .. matchId .. "}:coins", coinsPos[index] .. ":" .. coinsPos[index + 1], 1)
    table.insert(result, index)
end

return result
