Advertisement
Bolodefchoco_LUAXML

[Math] math.somarial

Dec 29th, 2015
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.45 KB | None | 0 0
  1. --Creator: Bolodefchoco
  2. --Made in: 29/12/2015
  3. --Last update: 23/05/2016
  4. --[[ Notes:
  5.     Does:
  6.         Retorna um fatorial ou um somatório do número dado.
  7.     Args:
  8.         x --> Número
  9.         t --> Tipo
  10.             0 --> Fatorial (3 = 1*2*3 = 6)
  11.             1 --> Somatório (5 = 5+4+3+2+1 = 15)
  12. ]]--
  13.  
  14. math.somarial=function(x,t)
  15.     if x == 1 then return 1 end
  16.     if t == 0 then
  17.         return x * math.somarial(x-1,0)
  18.     elseif t == 1 and x > 0 then
  19.         return x + math.somarial(x-1,1)
  20.     end
  21. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement