ViniCastilho

Caesar_TableInt.lua

Dec 1st, 2020
511
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Split(_int)
  2.     local split = {}
  3.     local sInt = tostring(_int)
  4.     for i = #sInt, 1, -1 do
  5.         split[#split+1] = tonumber(sInt:sub(i,i))
  6.     end
  7.     return split
  8. end
  9.  
  10. function SplitS(_sInt)
  11.     local split = {}
  12.     for i = #_sInt, 1, -1 do
  13.         split[#split+1] = tonumber(sInt:sub(i,i))
  14.     end
  15.     return split
  16. end
  17.  
  18. function Group(_split)
  19.     local sInt = ""
  20.     for i = #_split, 1, -1 do
  21.         sInt = sInt .. _split[i]
  22.     end
  23.     return tonumber(sInt)
  24. end
  25.  
  26. function GroupS(_split)
  27.     local sInt = ""
  28.     for i = #_split, 1, -1 do
  29.         sInt = sInt .. _split[i]
  30.     end
  31.     return sInt
  32. end
  33.  
  34. function Step(_split,_index)
  35.     if _split[_index] >= 10 then
  36.         _split[_index+1] = _split[_index+1] or 0
  37.         _split[_index+1] = _split[_index+1] + math.floor(_split[_index]/10)
  38.         _split[_index] = _split[_index] % 10
  39.     end
  40. end
  41.  
  42. function Add(_intA,_intB,_r)
  43.     local sA = Split(_intA)
  44.     local sB = Split(_intB)
  45.     local sR = {}
  46.     local i = 1
  47.     while sA[i] ~= nil or sB[i] ~= nil do
  48.         sA[i] = sA[i] or 0
  49.         sB[i] = sB[i] or 0
  50.         sR[i] = sR[i] or 0
  51.         sR[i] = sR[i] + (sA[i] + sB[i])
  52.         Step(sR,i)
  53.         i = i + 1
  54.     end
  55.     if _r == nil then
  56.         return Group(sR)
  57.     else
  58.         return GroupS(sR)
  59.     end
  60. end
  61.  
  62. function Mul(_intA,_intB,_r)
  63.     local sA = Split(_intA)
  64.     local sB = Split(_intB)
  65.     local sR = {}
  66.     for i = 1, #sA do
  67.         sA[i] = sA[i] or 0
  68.         for j = 1, #sB do
  69.             sB[j] = sB[j] or 0
  70.             sR[j+(i-1)] = sR[j+(i-1)] or 0
  71.             sR[j+(i-1)] = sR[j+(i-1)] + (sA[i] * sB[j])
  72.             Step(sR,j+(i-1))
  73.         end
  74.     end
  75.     if _r == nil then
  76.         return Group(sR)
  77.     else
  78.         return GroupS(sR)
  79.     end
  80. end
  81.  
  82. function Pow(_intBase,_intExponent,_r)
  83.     local rInt = 1
  84.     for i = 1, _intExponent do
  85.         rInt = Mul(rInt,_intBase,_r)
  86.     end
  87.     return rInt
  88. end
  89.  
  90. function Mod(_intN,_intM)
  91.     sN = Split(_intN)
  92.     sInt = ""
  93.     for i = #sN, 1, -1 do
  94.         sInt = sInt .. sN[i]
  95.         sInt = tonumber(sInt) % _intM
  96.     end
  97.     return sInt
  98. end
RAW Paste Data