ノート:Tournament

提供: Wikiducca
2017年10月19日 (木) 22:03時点におけるかにふとん (ノート | 投稿記録)による版

(差分) ←前の版 | 最新版 (差分) | 次の版→ (差分)
移動: 案内検索

local p = {}

function p.main(frame) local args = frame.args local team = {} local nRow = { [0] = {} } local line = {}

local i = 1 while args[i] ~= "result" do team[i] = args[i] nRow[0][i] = 1 i = i + 1 end local nTeam = i - 1 i = i + 1

local round = 1 local curr = 1 local prev = 1 local row = 0 nRow[1] = {} while args[i] ~= nil do if args[i] == "bye" then nRow[round][curr] = nRow[round-1][prev] nRow[round][curr+1] = nRow[round-1][prev+1] prev = prev + 2 i = i + 1 else if nRow[round-1][prev+2] == nil then break end local prev1 = nRow[round-1][prev+1] local prev2 = nRow[round-1][prev+2] local curr1 if prev1 > prev2 then curr1 = (prev1 + prev2 + (curr1 % 2)) / 2 else curr1 = (prev1 + prev2 - (curr1 % 2)) / 2 end local curr2 = (prev1 + prev2) - curr1 nRow[round][curr] = nRow[round-1][prev] + curr1 nRow[round][curr+1] = nRow[round-1][prev+3] + curr2 prev = prev + 4 i = i + 4 end row = row + nRow[round][curr] + nRow[round][curr+1] if row == nTeam then round = round + 1 curr = 1 prev = 1 row = 0 nRow[round] = {} else curr = curr + 2 end end

return "" end

return p