-
-
Save khushmeeet/219057a143fcc2e9321f2b1266877910 to your computer and use it in GitHub Desktop.
Factorial in python using y-combinator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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