Lets see, what about factorial in constant memory? Exponentiation (a to the power of b, where they are positive integers) in logarithmic time (not using built-in exponentiation functions/syntax)? Anonymously add a constant to a number and return it (in a way that can be passed to a function like 'map' or some such)?
def Factorial(x):
output = 1
for i in xrange(x):
output *= (i + 1)
return output
def Factorial2(x):
return reduce(operator.mul, xrange(1, x + 1), 1)
I provided two versions, both with constant memory, to show how it'd look with explicit iteration and without it.
With this, I get:
>>> Factorial(200)
788657867364790503552363213932185062295135977687173263294742533244359449963403342920304284011984623904177212138919638830257642790242637105061926624952829931113462857270763317237396988943922445621451664240254033291864131227428294853277524242407573903240321257405579568660226031904170324062351700858796178922222789623703897374720000000000000000000000000000000000000000000000000L
Exponentiation:
def Power(a, b):
if not b:
return 1
if b % 2:
return Power(a, b - 1) * a
x = Power(a, b/2)
return x * x
Add a constant:
lambda x: x + 7
Or, if you want to name it globally:
def TweakValue(x):
return x + 7
How do they look in Perl?