Advertisement
Bolodefchoco_LUAXML

[Math] math.triapas

Nov 1st, 2016
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.64 KB | None | 0 0
  1. --Creator: Bolodefchoco
  2. --Made in: 01/11/2016
  3. --Last update: 01/11/2016
  4. --[[ Notes:
  5.     Does:
  6.         Retorna o triângulo de pascal em forma de tabela e texto
  7.     Args:
  8.         row --> Número de linhas
  9. ]]--
  10.  
  11. math.triapas = function(row)
  12.     local toRet,strToRet = {},""
  13.     local m = {}
  14.     for i = 1,row+1 do
  15.         toRet[i] = {}
  16.         local x = {}
  17.         for j = 0,i-1 do
  18.             if j == 0 or j == (i-1) then
  19.                 x[j] = 1
  20.             else
  21.                 x[j] = (m[j] or 0) + (m[j-1] or 0)
  22.             end
  23.             toRet[i][j+1] = x[j]
  24.             strToRet = strToRet .. (j==0 and (" "):rep((row+1)-i) or "") .. x[j] .. " "
  25.         end
  26.         m = x
  27.         strToRet = strToRet .. "\n"
  28.     end
  29.     return toRet,strToRet
  30. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement