Last active
August 12, 2016 18:12
-
-
Save v-kolesnikov/1057b17de96f8522f4277ae5c4027afb to your computer and use it in GitHub Desktop.
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
(defn factorial [n] | |
(let [y (fn [f] (f f)) | |
f (fn [g] (fn [n] (if (zero? n) 1 (* n ((g g) (dec n))))))] | |
((y f) n))) |
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 y = (f) => f(f); | |
const f = (g) => (n) => (n === 0 ? 1 : (n * (g(g)(n - 1)))); | |
export default (x) => y(f)(x); |
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 factorial(n) | |
y = -> (f) { f.(f) } | |
f = -> (g) { -> (n) { n == 0 ? 1 : n * g.(g).(n - 1) } } | |
y.(f).(n) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment