Advertisement
zigwin

Pascal's Triangle

Feb 2nd, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.71 KB | None | 0 0
  1. do
  2.  
  3.  
  4. -- [[ Settings ]] --
  5.  
  6. local height = 40
  7. local offset = 1650
  8.  
  9. -- [[ Main ]] --
  10.  
  11. local list = {{1},{1, 1}}
  12. --[[
  13.                 i
  14.     {1}         1
  15.    {1,1}        2
  16.   {1,2,1}       3
  17.  {1,3,3,1}      4
  18. {1,4,6,4,1}     5
  19.     ...        ...
  20. --]]
  21. if height > 2 then
  22.     for i=3, height do
  23.         table.insert(list, {})
  24.         for length=1, i do
  25.             local add = ( list[i-1][length-1] or 0 ) + ( list[i-1][length] or 0 )
  26.             table.insert(list[i], add)
  27.             print( ( list[i-1][length-1] or 0 ) .. "+" .. ( list[i-1][length] or 0 ))
  28.         end
  29.     end
  30. end
  31.  
  32. for i=1, height do
  33.     local left = height * 50 - i*25
  34.     for length=1, i do
  35.         ui.addTextArea(i*100+length, list[i][length], nil, length*50+left - offset, i*10, 0, 0, 0, 0)
  36.     end
  37. end
  38.  
  39. -- [[ End ]]  --
  40.  
  41. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement