I'm trying to understand if the following Python function:
def factorial(i):
if not hasattr(factorial, 'lstFactorial'):
factorial.lstFactorial = [None] * 1000
if factorial.lstFactorial[i] is None:
iProduct = 1
for iFactor in xrange(1, i+1):
iProduct *= iFactor
factorial.lstFactorial[i] = iProduct
return factorial.lstFactorial[i]
would produce the same results as the equivalent in C#:
long factorial(long n)
{
return n <= 1 ? 1 : n * factorial(n-1);
}
for a value of 12 or less.
I know nothing about Python but have just converted some Python code to C#. This was the only function that I didn't fully understand.
here is main algorithm
iProduct = 1
for iFactor in xrange(1, i+1):
iProduct *= iFactor
other code is for caching results.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With