Skip to content

Instantly share code, notes, and snippets.

@khushmeeet
Created November 30, 2017 14:13
Show Gist options
  • Save khushmeeet/219057a143fcc2e9321f2b1266877910 to your computer and use it in GitHub Desktop.
Save khushmeeet/219057a143fcc2e9321f2b1266877910 to your computer and use it in GitHub Desktop.
Factorial in python using y-combinator
def Y(f):
def g(h):
return lambda x: f(h(h))(x)
return g(g)
def q(r):
return lambda x: 1 if x == 0 else x * r(x - 1)
factorial = Y(q)
print(factorial(5))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment