Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
test123
function dump (tbl, indent) if not indent then indent = 0 end local toprint = string.rep(" ", indent) .. "{\r\n" indent = indent + 2 for k, v in pairs(tbl) do toprint = toprint .. string.rep(" ", indent) if (type(k) == "number") then toprint = toprint .. "[" .. k .. "] = " elseif (type(k) == "string") then toprint = toprint .. k .. "= " end if (type(v) == "number") then toprint = toprint .. v .. ",\r\n" elseif (type(v) == "string") then toprint = toprint .. "\"" .. v .. "\",\r\n" elseif (type(v) == "table") then toprint = toprint .. dump(v, indent + 2) .. ",\r\n" else toprint = toprint .. "\"" .. tostring(v) .. "\",\r\n" end end toprint = toprint .. string.rep(" ", indent-2) .. "}" return toprint end local items = { bandage = 2, bow = 4, gold = 1 } local total_rate = 0 for k, v in pairs(items) do total_rate = total_rate + v end local rates = {} for k, v in pairs(items) do rates[#rates + 1] = {id = k, rate = v / total_rate} end for k = 2, #rates do if k ~= 1 then rates[k].rate = rates[k - 1].rate + rates[k].rate end end print(dump(rates))
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
Creating habits v3, Lua
Roots without the math library in Lua
Basic class example
test123
wwww
Monty Hall Problem Simulated
Area of Sector Calculator
BasicTablePrinter
Properties in Lua
Goalless DRAWS
Please log in to post a comment.