Skip to content

Instantly share code, notes, and snippets.

@alexlouden
Created January 17, 2013 02:14
Show Gist options
  • Save alexlouden/4552918 to your computer and use it in GitHub Desktop.
Save alexlouden/4552918 to your computer and use it in GitHub Desktop.
def factorial(x):
result = 1
for i in xrange(1, x + 1):
result *= i
return result
######################################################################
def _if(test):
return lambda alternative: \
lambda result: \
[delay(result), delay(alternative)][not not test]()
def delay(f):
if callable(f): return f
else: return lambda: f
fact = lambda n: _if (n <= 1) (1) (lambda: n * fact(n-1))
fact(100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment