Module:Sandbox/AnataBakka

-- local p    = {} local lib  = require('Module:Feature')

function p.test(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end local persona={} local s="" local highest local smallest for n=1,10 do           persona[n] = {} end for o = 0, 15 do       for p=1,10 do            for n=p+1,10 do                persona[p][n]=0 end end highest,smallest=nil,nil local alreadytaken={} local stop = 1 while stop<=15 do           local i=math.random(6) local j=math.random(i+1,7) local k=math.random(j+1,8) local l=math.random(k+1,9) local m=math.random(l+1,10) if alreadytaken[i..j..k..l..m] == nil then alreadytaken[i..j..k..l..m] = 1 local firstteam={} local secondteam={} for n=1,10 do                   if n == i or n == j or n == k or n == l or n == m then table.insert(firstteam,n) else table.insert(secondteam,n) end end s = s .. " "               for index,p in pairs (firstteam) do                    for index2,n in pairs (firstteam) do                        if index2 > index then persona[p][n] = persona[p][n] + 1 end end s = s .. " " .. p               end s = s .. " VS" for index,p in pairs (secondteam) do                   for index2,n in pairs (secondteam) do                        if index2 > index then persona[p][n] = persona[p][n] + 1 end end s = s .. " " .. p               end stop=stop+1 end end for p=1,10 do           for n=p+1,10 do                if highest == nil then highest = persona[p][n] smallest = persona[p][n] else if persona[p][n]>highest then highest = persona[p][n] end if persona[p][n]<smallest then smallest = persona[p][n] end end end end s = s .. " "   end return s end

function p.ap(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end local values="" local orig=args local count=6 local fill local formula if args["skill"]=="R" then fill=3 else fill=5 end i=1 local temp,a,b,c local round=args["round"] or nil while orig[i]~=nil and orig[i]~="" do       if (string.find(orig[i],"to")~=nil or string.find(orig[i],"x")~=nil) and string.find(orig[i],"%<")==nil then local _, occurences = string.gsub(orig[i], "to", "") if string.find(orig[i],"x")==nil and occurences == 1 then start,finish,times=orig[i]:match"(.*) *to *([^ ]*) *([^ ]*)" if start~=nil and finish~=nil and pcall(expr,start.."*2")~=false and pcall(expr,finish.."*2")~=false then start=tonumber(expr(start)) finish=tonumber(expr(finish)) if times=="" or times==nil then times=fill fill=0 else times=tonumber(expr(times)) end count=count-times if count<0 then return userError("Maximum size exceeded", "LuaError") end x=1 while x<=times do                       if x==1 then formula = start scale = (finish - start) / (times - 1) else formula = formula + scale end if values=="" then values=fd(rounding(formula,round)) else values=values.." / "..fd(rounding(formula,round)) end x=x+1 end else count=count-1 if count<0 then return userError("Maximum size exceeded", "LuaError") end if values=="" then values=fd(rounding(expr(orig[i]),round)) else values=values.." / "..fd(rounding(expr(orig[i]),round)) end end else if last(orig[i]," ") ~= last(orig[i],"to ") then times = last(orig[i]," ") orig[i] = string.sub(orig[i],1,#orig[i]-#times) end if times=="" or times==nil then times=fill fill=0 else times=tonumber(expr(times)) end if occurences >1 then while string.find(orig[i], "to") ~= nil do                       local to = mw.text.split(orig[i], "to") local _, occurences1 = string.gsub(to[1], "%(", "")                       local _, occurences2 = string.gsub(to[2], "%)", "") local para1 = mw.text.split(to[1], "%(")                       local para2 = mw.text.split(to[2], "%)") local start,finish="","" local times2 local occurences3=0 local j = occurences1 + 1 while j >= 2 do                           if j == occurences1+1 then start=para1[j] else start = "(" .. para1[j] .. start                           end                            _, times2 = string.gsub(para1[j], "%)", "") occurences3 = occurences3 + times2 if occurences1 + 2 - j > occurences3 then break end j = j - 1 end occurences3=0 j = 1 while j <= occurences2 do                           if j == 1 then finish = para2[j] else finish = finish .. para2[j] .. ")"                           end                            _, times2 = string.gsub(para2[j], "%(", "") occurences3 = occurences3 + times2 if j > occurences3 then break end j = j + 1 end orig[i] = string.gsub(orig[i], start .. "to" .. finish, start .. "+(" .. finish.. "-" .. start .. ")/(" .. times .. "-1)*(x-1)") end end useformula = orig[i] if useformula~=nil and pcall(expr,string.gsub(useformula,"x","1").."*2")~=false then x=1 while x<=times do                       count=count-1 if count<0 then return userError("Maximum size exceeded", "LuaError") end formula=string.gsub(useformula,"x",x) if values=="" then values=fd(rounding(expr(formula),round)) else values=values.." / "..fd(rounding(expr(formula),round)) end x=x+1 end else count=count-1 if count<0 then return userError("Maximum size exceeded", "LuaError") end if values=="" then values=fd(rounding(expr(args[i]),round)) else values=values.." / "..fd(rounding(expr(args[i]),round)) end end end else count=count-1 if count<0 then return userError("Maximum size exceeded", "LuaError") end if values=="" then values=fd(rounding(expr(args[i]),round)) else values=values.." / "..fd(rounding(expr(args[i]),round)) end end i=i+1 end return values end

function expr(val) if string.find(val,"[0-9]")==nil then return val end local val=string.gsub(string.gsub(string.gsub(string.gsub(string.gsub(string.gsub(string.gsub(string.gsub(val," ",""),"%/"," / "),"%*"," * "),"%+"," + "),"%-"," - "),"%^"," %^ "),"([^%d%(%)]) %- ","%1-"),"([^%d%(%)]) %+ ","%1+") local i=1 local j=1 local a,b,switcher,switcher2,switcher3,temp while i>0 do       while j>0 do            temp=val if string.find(val,"%)")~=nil then               switchertemp=mw.text.split( val, "%)") temp=last(switchertemp[1],"%(")           end            if string.find(temp," %^ ")~=nil then                a=mw.text.split(temp," %^ ")                b=mw.text.split(a[2]," ")                switcher=last( a[1]," ")                switcher2=b[1]                switcher3=switcher^switcher2                if string.find(switcher2,"%-")~=nil then                     switcher2="%-"..switcher2*(-1)                end                val=string.gsub(val,switcher.." %^ "..switcher2,switcher3)                break            end            if string.find(temp," %/ ")~=nil then                a=mw.text.split(temp," %/ ")                b=mw.text.split(a[2]," ")                switcher=last( a[1]," ")                switcher2=b[1]                switcher3=switcher/switcher2                if string.find(switcher2,"%-")~=nil then                     switcher2="%-"..switcher2*(-1) end val=string.gsub(val,switcher.." %/ "..switcher2,switcher3) break end if string.find(temp," %* ")~=nil then a=mw.text.split( temp," %* ") b=mw.text.split(a[2]," ") switcher=last( a[1]," ") switcher2=b[1] switcher3=switcher*switcher2 if string.find(switcher2,"%-")~=nil then switcher2="%-"..switcher2*(-1) end val=string.gsub(val,switcher.." %* "..switcher2,switcher3) break end if string.find(temp," %- ")~=nil then a=mw.text.split( temp," %- ") b=mw.text.split(a[2]," ") switcher=last( a[1]," ") switcher2=b[1] if switcher=="" then if string.find(switcher2,"%-")~=nil then switcher2="%-"..switcher2*(-1) end val=string.gsub(val," %- "..switcher2,"%-"..switcher2) break else switcher3=switcher-switcher2 if string.find(switcher2,"%-")~=nil then switcher2="%-"..switcher2*(-1) end val=string.gsub(val,switcher.." %- "..switcher2,switcher3) break end end if string.find(temp," %+ ")~=nil then a=mw.text.split( temp," %+ ") b=mw.text.split(a[2]," ") switcher=last( a[1]," ") switcher2=b[1] if switcher=="" then if string.find(switcher2,"%-")~=nil then switcher2="%-"..switcher2*(-1) end val=string.gsub(val," %+ "..switcher2,switcher2) break else switcher3=switcher+switcher2 if string.find(switcher2,"%-")~=nil then switcher2="%-"..switcher2*(-1) end val=string.gsub(val,switcher.." %+ "..switcher2,switcher3) break end end if string.find(val,"%)")~=nil and string.find(val,"%(")~=nil then if string.find(temp,"%-")~=nil then temp="%-"..temp*(-1) end val=string.gsub(val,"%("..temp.."%)",temp) break else i=0 end break end end return temp end

function last(val,sign) local a=mw.text.split(val,sign) local j=1 while j>0 do       if a[j] ~=nil then j=j+1 else break end end return a[j-1] end

function fd(val) if string.find(val,"[0-9]") == nil or string.find(val,"%.") == nil then return val end local a,b,c if string.find(val,"span") ~= nil then a,b,c = val:match"([^.]*).(.*) (.*)" if string.find(val,"span")<=string.find(val,"%.") then return a .. ". " .. b .. " " .. c       else return a .. ". " .. b .. " " .. c       end else a,b,c = val:match"([^.]*).([0-9]*)(.*)" return a .. ". " .. b .. " " .. c   end end

function fdmulti(val) if string.find(val,"[0-9]") == nil or string.find(val,"%.") == nil then return val end local val   = mw.text.split(val,"%.") local values = val[1] local i     = 2 local b,c while val[i] ~= nil do       if string.find(val[i],"span") ~= nil then b,c   = val[i]:match"(.*) (.*)" if string.find(tostring(b),"[0-9]")==nil then values=values.."."..val[i] else if string.find(val[i],"span")<=string.find(val[i],"%.") then values = values .. ". " .. b .. " " .. c               else values = values .. ". " .. b .. " " .. c               end end else b,c   = val[i]:match"([0-9]*)(.*)" if string.find(tostring(b),"[0-9]")==nil then values=values.."."..val[i] else values = values .. ". " .. b .. " " .. c           end end i = i + 1 end return values end

function rounding(val, decimals) local round local val = tostring(val) if decimals == nil or string.find(val,"[0-9]") == nil or string.find(val,"<span") ~= nil or string.find(val,"%.") == nil then return val end local a,b,c,d a,b,c,d = val:match"([^0-9]*)([0-9]*).([0-9]*)(.*)" val=tonumber(b.."."..c)   if decimals == "abs" then round = math.abs(val) end if decimals == "floor" then round = math.floor(val) end if decimals == "ceil" then round = math.ceil(val) end if decimals == "trunc" then round = string.sub(val,1,(string.find(val,"%.") or 0) - 1) end if round == nil then local mult = 10^(decimals) round = math.floor(val * mult + 0.5) / mult end return a..round..d end

return p --