Module:FEHStatUtil/sandbox

local ListUtil = require 'Module:ListUtil'

local arrayOrder = function (arr) return ListUtil.map(arr, function (lhs, i)   return ListUtil.count(ListUtil.map(arr, function (rhs, j)      return (i = rhs) or (i > j and lhs > rhs)    end), true)  end) end

local getMasterGrowthRate = function (rarity, rate) return math.floor(rate * (0.79 + 0.07 * rarity)) end

local getGrowthValue = function (rarity, rate) return math.floor(0.39 * getMasterGrowthRate(rarity, rate)) end

local findGrowthRate = function (rarity, growth) for rate = 0,210,5 do   if getGrowthValue(rarity, rate) == growth then return rate, false end end for rate = 210,0,-1 do   if getGrowthValue(rarity, rate) == growth then return rate, true end end end

local fullLv1Stats = function (fiveStarLv1Stats) local order = {0, unpack(arrayOrder(ListUtil.sub(fiveStarLv1Stats, 2, 5)))} return ListUtil.generate(5, function (rarity)   return ListUtil.zip(fiveStarLv1Stats, order, function (b, o)      return b - math.floor((5 - rarity + (o < 2 and 1 or 0)) / 2) end) end) end

local fullLv40Stats = function (rateSet, full1StatSet) return ListUtil.map(full1StatSet, function (statSet, rarity)   return ListUtil.zip(statSet, rateSet, function (base, rate) return base + getGrowthValue(rarity, rate) end) end) end

return { getGrowthRate = getGrowthRate, getGrowthValue = getGrowthValue, findGrowthRate = findGrowthRate, fullLv1Stats = fullLv1Stats, fullLv40Stats = fullLv40Stats, }