Last active
July 19, 2021 14:46
-
-
Save keller/8589abe5431d62c6568e2af15414989a to your computer and use it in GitHub Desktop.
Linked to from twitter
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
curl -s https://gist.githubusercontent.com/keller/8589abe5431d62c6568e2af15414989a/raw/de15e6030a078dba18386dcb457e063e8d8e458f/fizzbuzz_min.js | node - |
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
deno run https://gist.githubusercontent.com/keller/8589abe5431d62c6568e2af15414989a/raw/de15e6030a078dba18386dcb457e063e8d8e458f/fizzbuzz_min.js |
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
const ZERO = f => a => a; | |
const ONE = f => a => f(a); | |
const SUCC = n => f => a => f(n(f)(a)); | |
const TWO = SUCC(ONE); | |
const THREE = SUCC(TWO); | |
const ADD = x => y => x(SUCC)(y); | |
const FIVE = ADD(TWO)(THREE); | |
const MULT = x => y => f => x(y(f)); | |
const TEN = MULT(FIVE)(TWO); | |
const ONE_HUNDRED = MULT(TEN)(TEN); | |
const TRUE = x => y => x; | |
const FALSE = x => y => y; | |
const PAIR = x => y => f => f(x)(y); | |
const CAR = p => p(x => y => x); | |
const CDR = p => p(x => y => y); | |
const PHI = p => PAIR(CDR(p))(SUCC(CDR(p))); | |
const PRED = n => CAR(n(PHI)(PAIR(ZERO)(ZERO))); | |
const SUB = x => y => y(PRED)(x); | |
const IS_ZERO = n => n(x => FALSE)(TRUE); | |
const LEQ = x => y => IS_ZERO(SUB(x)(y)); | |
const Y = f => (x => f(y => x(x)(y)))(x => f(y => x(x)(y))); | |
const MOD = Y(f => x => y => LEQ(y)(x)(z => f(SUB(x)(y))(y)(z))(x)); | |
const AND = x => y => x(y)(FALSE); | |
ONE_HUNDRED(x => | |
FALSE( | |
AND(IS_ZERO(MOD(x)(THREE)))(IS_ZERO(MOD(x)(FIVE)))(FIZZBUZZ)( | |
IS_ZERO(MOD(x)(THREE))(FIZZ)( | |
IS_ZERO(MOD(x)(FIVE))(BUZZ)(y => PRINT_NUM(x)) | |
) | |
)(x) | |
)(SUCC(x)) | |
)(ONE); | |
// --- JS helpers. not strict lambda calc below | |
function PRINT_NUM(n) { | |
console.log(n(x => x + 1)(0)); | |
} | |
function FIZZBUZZ() { | |
console.log("FIZZBUZZ"); | |
} | |
function FIZZ() { | |
console.log("FIZZ"); | |
} | |
function BUZZ() { | |
console.log("BUZZ"); | |
} |
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
(l => i => b => u => | |
(p => | |
(x => y => z => x(y(z)))( | |
(x => y => z => x(y(z)))( | |
(x => y => x(x => y => z => y(x(y)(z)))(y))( | |
(x => y => z => y(x(y)(z)))(x => y => x(y)) | |
)( | |
(x => y => z => y(x(y)(z)))( | |
(x => y => z => y(x(y)(z)))(x => y => x(y)) | |
) | |
) | |
)((x => y => z => y(x(y)(z)))(x => y => x(y))) | |
)( | |
(x => y => z => x(y(z)))( | |
(x => y => x(x => y => z => y(x(y)(z)))(y))( | |
(x => y => z => y(x(y)(z)))(x => y => x(y)) | |
)( | |
(x => y => z => y(x(y)(z)))( | |
(x => y => z => y(x(y)(z)))(x => y => x(y)) | |
) | |
) | |
)((x => y => z => y(x(y)(z)))(x => y => x(y))) | |
)(x => | |
(x => y => y)( | |
(x => y => x(y)(x => y => y))( | |
(x => x(x => x => y => y)(x => y => x))( | |
(x => (y => x(z => y(y)(z)))(y => x(z => y(y)(z))))(f => x => y => | |
(x => y => | |
(x => x(x => x => y => y)(x => y => x))( | |
(x => y => | |
y(x => | |
(x => x(x => y => x))( | |
x(x => | |
(x => y => z => z(x)(y))((x => x(x => y => y))(x))( | |
(x => y => z => y(x(y)(z)))( | |
(x => x(x => y => y))(x) | |
) | |
) | |
)((x => y => z => z(x)(y))(x => y => y)(x => y => y)) | |
) | |
)(x))(x)(y) | |
))(y)(x)(z => | |
f( | |
(x => y => | |
y(x => | |
(x => x(x => y => x))( | |
x(x => | |
(x => y => z => z(x)(y))((x => x(x => y => y))(x))( | |
(x => y => z => y(x(y)(z)))( | |
(x => x(x => y => y))(x) | |
) | |
) | |
)((x => y => z => z(x)(y))(x => y => y)(x => y => y)) | |
) | |
)(x))(x)(y) | |
)(y)(z) | |
)(x) | |
)(x)( | |
(x => y => z => y(x(y)(z)))( | |
(x => y => z => y(x(y)(z)))(x => y => x(y)) | |
) | |
) | |
) | |
)( | |
(x => x(x => x => y => y)(x => y => x))( | |
(x => (y => x(z => y(y)(z)))(y => x(z => y(y)(z))))(f => x => y => | |
(x => y => | |
(x => x(x => x => y => y)(x => y => x))( | |
(x => y => | |
y(x => | |
(x => x(x => y => x))( | |
x(x => | |
(x => y => z => z(x)(y))((x => x(x => y => y))(x))( | |
(x => y => z => y(x(y)(z)))( | |
(x => x(x => y => y))(x) | |
) | |
) | |
)((x => y => z => z(x)(y))(x => y => y)(x => y => y)) | |
) | |
)(x))(x)(y) | |
))(y)(x)(z => | |
f( | |
(x => y => | |
y(x => | |
(x => x(x => y => x))( | |
x(x => | |
(x => y => z => z(x)(y))((x => x(x => y => y))(x))( | |
(x => y => z => y(x(y)(z)))( | |
(x => x(x => y => y))(x) | |
) | |
) | |
)((x => y => z => z(x)(y))(x => y => y)(x => y => y)) | |
) | |
)(x))(x)(y) | |
)(y)(z) | |
)(x) | |
)(x)( | |
(x => y => x(x => y => z => y(x(y)(z)))(y))( | |
(x => y => z => y(x(y)(z)))(x => y => x(y)) | |
)( | |
(x => y => z => y(x(y)(z)))( | |
(x => y => z => y(x(y)(z)))(x => y => x(y)) | |
) | |
) | |
) | |
) | |
)(x => l(u))( | |
(x => x(x => x => y => y)(x => y => x))( | |
(x => (y => x(z => y(y)(z)))(y => x(z => y(y)(z))))(f => x => y => | |
(x => y => | |
(x => x(x => x => y => y)(x => y => x))( | |
(x => y => | |
y(x => | |
(x => x(x => y => x))( | |
x(x => | |
(x => y => z => z(x)(y))((x => x(x => y => y))(x))( | |
(x => y => z => y(x(y)(z)))( | |
(x => x(x => y => y))(x) | |
) | |
) | |
)((x => y => z => z(x)(y))(x => y => y)(x => y => y)) | |
) | |
)(x))(x)(y) | |
))(y)(x)(z => | |
f( | |
(x => y => | |
y(x => | |
(x => x(x => y => x))( | |
x(x => | |
(x => y => z => z(x)(y))((x => x(x => y => y))(x))( | |
(x => y => z => y(x(y)(z)))( | |
(x => x(x => y => y))(x) | |
) | |
) | |
)((x => y => z => z(x)(y))(x => y => y)(x => y => y)) | |
) | |
)(x))(x)(y) | |
)(y)(z) | |
)(x) | |
)(x)( | |
(x => y => z => y(x(y)(z)))( | |
(x => y => z => y(x(y)(z)))(x => y => x(y)) | |
) | |
) | |
)(x => l(i))( | |
(x => x(x => x => y => y)(x => y => x))( | |
(x => (y => x(z => y(y)(z)))(y => x(z => y(y)(z))))(f => x => y => | |
(x => y => | |
(x => x(x => x => y => y)(x => y => x))( | |
(x => y => | |
y(x => | |
(x => x(x => y => x))( | |
x(x => | |
(x => y => z => z(x)(y))((x => x(x => y => y))(x))( | |
(x => y => z => y(x(y)(z)))( | |
(x => x(x => y => y))(x) | |
) | |
) | |
)((x => y => z => z(x)(y))(x => y => y)(x => y => y)) | |
) | |
)(x))(x)(y) | |
))(y)(x)(z => | |
f( | |
(x => y => | |
y(x => | |
(x => x(x => y => x))( | |
x(x => | |
(x => y => z => z(x)(y))((x => x(x => y => y))(x))( | |
(x => y => z => y(x(y)(z)))( | |
(x => x(x => y => y))(x) | |
) | |
) | |
)((x => y => z => z(x)(y))(x => y => y)(x => y => y)) | |
) | |
)(x))(x)(y) | |
)(y)(z) | |
)(x) | |
)(x)( | |
(x => y => x(x => y => z => y(x(y)(z)))(y))( | |
(x => y => z => y(x(y)(z)))(x => y => x(y)) | |
)( | |
(x => y => z => y(x(y)(z)))( | |
(x => y => z => y(x(y)(z)))(x => y => x(y)) | |
) | |
) | |
) | |
)(x => l(b))(x => p(x)) | |
) | |
)(x) | |
)((x => y => z => y(x(y)(z)))(x)) | |
)(x => y => x(y)))(n => l(n(x => x + 1)(0))))(console.log)("FIZZ")("BUZZ")( | |
"FIZZBUZZ" | |
); |
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
(l=>i=>b=>u=>(p=>(x=>y=>z=>x(y(z)))((x=>y=>z=>x(y(z)))((x=>y=>x(x=>y=>z=>y(x(y)(z)))(y))((x=>y=>z=>y(x(y)(z)))(x=>y=>x(y)))((x=>y=>z=>y(x(y)(z)))((x=>y=>z=>y(x(y)(z)))(x=>y=>x(y)))))((x=>y=>z=>y(x(y)(z)))(x=>y=>x(y))))((x=>y=>z=>x(y(z)))((x=>y=>x(x=>y=>z=>y(x(y)(z)))(y))((x=>y=>z=>y(x(y)(z)))(x=>y=>x(y)))((x=>y=>z=>y(x(y)(z)))((x=>y=>z=>y(x(y)(z)))(x=>y=>x(y)))))((x=>y=>z=>y(x(y)(z)))(x=>y=>x(y))))(x=>(x=>y=>y)((x=>y=>x(y)(x=>y=>y))((x=>x(x=>x=>y=>y)(x=>y=>x))((x=>(y=>x(z=>y(y)(z)))(y=>x(z=>y(y)(z))))(f=>x=>y=>(x=>y=>(x=>x(x=>x=>y=>y)(x=>y=>x))((x=>y=>y(x=>(x=>x(x=>y=>x))(x(x=>(x=>y=>z=>z(x)(y))((x=>x(x=>y=>y))(x))((x=>y=>z=>y(x(y)(z)))((x=>x(x=>y=>y))(x))))((x=>y=>z=>z(x)(y))(x=>y=>y)(x=>y=>y))))(x))(x)(y)))(y)(x)(z=>f((x=>y=>y(x=>(x=>x(x=>y=>x))(x(x=>(x=>y=>z=>z(x)(y))((x=>x(x=>y=>y))(x))((x=>y=>z=>y(x(y)(z)))((x=>x(x=>y=>y))(x))))((x=>y=>z=>z(x)(y))(x=>y=>y)(x=>y=>y))))(x))(x)(y))(y)(z))(x))(x)((x=>y=>z=>y(x(y)(z)))((x=>y=>z=>y(x(y)(z)))(x=>y=>x(y))))))((x=>x(x=>x=>y=>y)(x=>y=>x))((x=>(y=>x(z=>y(y)(z)))(y=>x(z=>y(y)(z))))(f=>x=>y=>(x=>y=>(x=>x(x=>x=>y=>y)(x=>y=>x))((x=>y=>y(x=>(x=>x(x=>y=>x))(x(x=>(x=>y=>z=>z(x)(y))((x=>x(x=>y=>y))(x))((x=>y=>z=>y(x(y)(z)))((x=>x(x=>y=>y))(x))))((x=>y=>z=>z(x)(y))(x=>y=>y)(x=>y=>y))))(x))(x)(y)))(y)(x)(z=>f((x=>y=>y(x=>(x=>x(x=>y=>x))(x(x=>(x=>y=>z=>z(x)(y))((x=>x(x=>y=>y))(x))((x=>y=>z=>y(x(y)(z)))((x=>x(x=>y=>y))(x))))((x=>y=>z=>z(x)(y))(x=>y=>y)(x=>y=>y))))(x))(x)(y))(y)(z))(x))(x)((x=>y=>x(x=>y=>z=>y(x(y)(z)))(y))((x=>y=>z=>y(x(y)(z)))(x=>y=>x(y)))((x=>y=>z=>y(x(y)(z)))((x=>y=>z=>y(x(y)(z)))(x=>y=>x(y)))))))(x=>l(u))((x=>x(x=>x=>y=>y)(x=>y=>x))((x=>(y=>x(z=>y(y)(z)))(y=>x(z=>y(y)(z))))(f=>x=>y=>(x=>y=>(x=>x(x=>x=>y=>y)(x=>y=>x))((x=>y=>y(x=>(x=>x(x=>y=>x))(x(x=>(x=>y=>z=>z(x)(y))((x=>x(x=>y=>y))(x))((x=>y=>z=>y(x(y)(z)))((x=>x(x=>y=>y))(x))))((x=>y=>z=>z(x)(y))(x=>y=>y)(x=>y=>y))))(x))(x)(y)))(y)(x)(z=>f((x=>y=>y(x=>(x=>x(x=>y=>x))(x(x=>(x=>y=>z=>z(x)(y))((x=>x(x=>y=>y))(x))((x=>y=>z=>y(x(y)(z)))((x=>x(x=>y=>y))(x))))((x=>y=>z=>z(x)(y))(x=>y=>y)(x=>y=>y))))(x))(x)(y))(y)(z))(x))(x)((x=>y=>z=>y(x(y)(z)))((x=>y=>z=>y(x(y)(z)))(x=>y=>x(y)))))(x=>l(i))((x=>x(x=>x=>y=>y)(x=>y=>x))((x=>(y=>x(z=>y(y)(z)))(y=>x(z=>y(y)(z))))(f=>x=>y=>(x=>y=>(x=>x(x=>x=>y=>y)(x=>y=>x))((x=>y=>y(x=>(x=>x(x=>y=>x))(x(x=>(x=>y=>z=>z(x)(y))((x=>x(x=>y=>y))(x))((x=>y=>z=>y(x(y)(z)))((x=>x(x=>y=>y))(x))))((x=>y=>z=>z(x)(y))(x=>y=>y)(x=>y=>y))))(x))(x)(y)))(y)(x)(z=>f((x=>y=>y(x=>(x=>x(x=>y=>x))(x(x=>(x=>y=>z=>z(x)(y))((x=>x(x=>y=>y))(x))((x=>y=>z=>y(x(y)(z)))((x=>x(x=>y=>y))(x))))((x=>y=>z=>z(x)(y))(x=>y=>y)(x=>y=>y))))(x))(x)(y))(y)(z))(x))(x)((x=>y=>x(x=>y=>z=>y(x(y)(z)))(y))((x=>y=>z=>y(x(y)(z)))(x=>y=>x(y)))((x=>y=>z=>y(x(y)(z)))((x=>y=>z=>y(x(y)(z)))(x=>y=>x(y))))))(x=>l(b))(x=>p(x))))(x))((x=>y=>z=>y(x(y)(z)))(x)))(x=>y=>x(y)))(n=>l(n(x=>x+1)(0))))(console.log)("FIZZ")("BUZZ")("FIZZBUZZ") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment