Does roblox support factorials?
For example;
print(5!)
Should print 120
There are currently no arithmetic operators
or functions
in the math library
to calculate this for us. We'd have to create this function
ourselves, but this shouldn't be too much of a problem. Here's how it would work:
-- Arguments: -- 1. "n" - the factorial number to calculate local function factorial(n) local total = 1 -- the current product of the factorial for i = 1,n do -- iterations of the number given total = total * i -- increase the product end -- end return total -- return the final answer end print(factorial(5)) -- > 120 print(factorial(4)) -- > 24
Hope that helped, if you need a bit more of an explanation on how this function works, just leave a comment and I'll get to it.