# a quick excercise in "lambda python"
# written Nov 2008 by efficientjelly

# a factorial function written entirely with just single-argumented lambdas
# and calls
fac = ((lambda p: p(p)(lambda q: lambda n: ((n(lambda e: lambda e:
  lambda a: a)(lambda i: lambda l: i))(lambda d: lambda c: c)
  (lambda m: (lambda m: lambda z: m(n(z)))(q(m)))((lambda c: lambda x:
  n(lambda g: lambda h: h(g(c)))(lambda u: x)(lambda u: u))))))
  (lambda s: lambda q: lambda w: q(s(s)(q))(w)))

# for converting between church numerals and python numbers (you need
# a few python functions and operators to manipulate them)
natural = lambda c: c(lambda x: x+1)(0)
church = lambda n: reduce(lambda x,y:
  (lambda n: lambda f: lambda x: f(n(f)(x)))(x), range(n), lambda f: lambda x: x)

# test!
# fac(10) is about the highest number computing in a few seconds on a core 2 CPU
print natural(fac(church(10)))

syntax highlighted by Code2HTML, v. 0.9.1