def factorial(n) result = 1 for i in range(1, n) result = result * i end return result end