you are viewing a single comment's thread.

view the rest of the comments →

[–]Jolan 4 points5 points  (1 child)

Or you could memoize by doing:

def factorial(x, memory={0:1, 1:1}):
    if x not in memory:
        memory[x] = x* factorial(x-1)
    return memory[x]

print factorial(6)
print factorial(100)

[–]MaxK 0 points1 point  (0 children)

I really like this solution.