Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Creator: Bolodefchoco
- --Made in: 01/11/2016
- --Last update: 01/11/2016
- --[[ Notes:
- Does:
- Retorna o triângulo de pascal em forma de tabela e texto
- Args:
- row --> Número de linhas
- ]]--
- math.triapas = function(row)
- local toRet,strToRet = {},""
- local m = {}
- for i = 1,row+1 do
- toRet[i] = {}
- local x = {}
- for j = 0,i-1 do
- if j == 0 or j == (i-1) then
- x[j] = 1
- else
- x[j] = (m[j] or 0) + (m[j-1] or 0)
- end
- toRet[i][j+1] = x[j]
- strToRet = strToRet .. (j==0 and (" "):rep((row+1)-i) or "") .. x[j] .. " "
- end
- m = x
- strToRet = strToRet .. "\n"
- end
- return toRet,strToRet
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement