Skip to content

Instantly share code, notes, and snippets.

@abersheeran

abersheeran/y.py

Created Apr 6, 2021
Embed
What would you like to do?
Y combinator. Python lambda.
Y = lambda g: (lambda f: g(lambda arg: f(f)(arg))) (lambda f: g(lambda arg: f(f)(arg)))
if __name__ == "__main__":
fib = Y(lambda f: lambda n: (1 if n < 3 else f(n-1) + f(n-2)))
print(fib(10))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment