Created
August 24, 2022 06:24
-
-
Save curegit/59004aadb29f8972e25faa79125845d4 to your computer and use it in GitHub Desktop.
Python で Zコンビネータ
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
fix = lambda f: (lambda g: g(g))(lambda g: f(lambda *args, **kwargs: g(g)(*args, **kwargs))) | |
fact = fix(lambda f: lambda n: 1 if n == 0 else n * f(n - 1)) | |
fib = fix(lambda f: lambda x: 1 if x == 0 else 1 if x == 1 else f(x - 1) + f(x - 2)) | |
gcd = fix(lambda f: lambda a, b: abs(a) if b == 0 else f(b, a % b)) | |
tarai = fix(lambda f: lambda x, y, z: y if x <= y else f(f(x - 1, y, z), f(y - 1, z, x), f(z - 1, x, y))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment