-
-
Save hirokiky/6896260 to your computer and use it in GitHub Desktop.
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
# -*- coding:utf-8 -*- | |
from __future__ import print_function | |
(lambda zero, one, succ, is_zero, pred, AND, IF, Y, undefined: | |
(lambda add, mul, sub: | |
(lambda GT, EQ: | |
(lambda rem, REP: | |
(lambda three, five, num_from_church: | |
(lambda fifteen, one_hundred: | |
(lambda fizzbuzz: | |
fizzbuzz(lambda _: print("fizzbuzz"))(lambda _: print("fizz"))(lambda _: print("buzz"))(lambda n: print(num_from_church(n)))(one)(one_hundred) | |
)( | |
(lambda on_fizzbuzz: (lambda on_fizz: (lambda on_buzz: (lambda on_default: (lambda start: (lambda end: REP(lambda n: IF(is_zero(rem(n)(fifteen)))(lambda : on_fizzbuzz(n))(lambda : IF(is_zero(rem(n)(three)))(lambda : on_fizz(n))(lambda : IF(is_zero(rem(n)(five)))(lambda : on_buzz(n))(lambda : on_default(n)))))(undefined)(start)(end))))))) # fizzbuzz | |
) | |
)( | |
mul(three)(five), # fifteen | |
mul(mul(five)(five))(add(one)(three)), # one_fundred | |
) | |
)( | |
succ(succ(one)), # three | |
succ(succ(succ(succ(one)))), # five | |
(lambda n: n(lambda x: x+1)(0)), # num_from_church | |
) | |
)(Y (lambda rec: (lambda m: (lambda n: (lambda m_: IF(is_zero(m_))(lambda : (EQ(m)(n)(zero)(m)))(lambda : rec(m_)(n)))(sub(m)(n))))), # rem | |
Y (lambda rec: (lambda f: (lambda _: (lambda i: (lambda j: IF(GT(i)(j))(lambda : rec(f)(f(i))(succ(i))(j))(lambda : undefined)))))), # REP | |
) | |
)( | |
(lambda m: (lambda n: is_zero(sub(m)(n)))), # GT | |
(lambda m: (lambda n: AND(is_zero(sub(n)(m)))(is_zero(sub(n)(m))))) #EQ | |
) | |
)( | |
(lambda m: (lambda n: n(succ)(m))), # add | |
(lambda m: (lambda n: (lambda f: (lambda x: n(m(f))(x))))), # mul | |
(lambda m: (lambda n: n(pred)(m))), # sub | |
) | |
)( | |
(lambda f: (lambda x: x)), # zero | |
(lambda f: (lambda x: f(x))), # one | |
(lambda n: (lambda f: (lambda x: f(n(f)(x))))), # succ | |
(lambda n: (lambda x: (lambda y: n(lambda z: y)(x)))), # is_zero | |
(lambda n: (lambda f: (lambda x: n((lambda g : lambda h: h(g(f))))(lambda u: x)(lambda u: u)))), # pred | |
(lambda x: (lambda y: x(y)(x))), # AND | |
(lambda p: (lambda x: (lambda y: p(x)(y)()))), # IF | |
(lambda g: (lambda x: (lambda m: g(x(x))(m)))(lambda x: (lambda m: g(x(x))(m)))), # Y | |
0 # undefined | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment