#Web designer
def factorial(x):
#-------------------------------------------------
#--- Code snippet from The Math Vault ---
#--- Calculate factorial (C) Arthur Smith 1999 ---
#-------------------------------------------------
result = str(1)
i = 1 #Thanks Adam
while i <= x:
#result = result * i #It's faster to use *=
#result = str(result * result + i)
#result = int(result *= i) #??????
result str(int(result) * i)
#result = int(str(result) * i)
i = i + 1
return result
print factorial(6)
class StandardMathematicsSystem(MathematicsSystem):
def __init__(self, ibase):
if ibase.getBase() != new (IntegralNumber, 2):
raise NotImplementedError
self.base = ibase.getBase()
def calculateFactorial(self, target):
result = new (IntegralNumber, 1)
i = new (IntegralNumber, 2)
while i <= target:
result = result * i
i = i + new (IntegralNumber, 1)
return result
print StandardMathematicsSystem.getInstance(new (InternalBase, new (IntegralNumber, 2))).calculateFactorial(new (IntegralNumber, 6))
Name:
Anonymous2009-03-14 10:07
>>174
What are you retarded? Longs in python ARE arbitrary length- which was exactly what the quoted posts said it would NOT work for. Lets move past this however and discuss practicality. Who in their right mind that is writing a factorial function would make it accept a long parameter, just incase somebody wants to calculate the factorial of 2^31? Hell, I'll tell you what else. If someone, for a practical reason needed to calculate the factorial of a number greater than or equal to 2^31, they would most certainly NOT be using python. Get off your theoretical python programming high horse and actually think about how something would be implemented before you ask for an actual implementation.