Skip to content

Instantly share code, notes, and snippets.

@v-kolesnikov
Last active August 12, 2016 18:12
Show Gist options
  • Save v-kolesnikov/1057b17de96f8522f4277ae5c4027afb to your computer and use it in GitHub Desktop.
Save v-kolesnikov/1057b17de96f8522f4277ae5c4027afb to your computer and use it in GitHub Desktop.
Y-Combinator
(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)))
const y = (f) => f(f);
const f = (g) => (n) => (n === 0 ? 1 : (n * (g(g)(n - 1))));
export default (x) => y(f)(x);
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