Skip to content

Instantly share code, notes, and snippets.

@howardlau1999
Created August 11, 2021 09:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save howardlau1999/9ef6060a2c5a8f7072ccda0f5bee487c to your computer and use it in GitHub Desktop.
Save howardlau1999/9ef6060a2c5a8f7072ccda0f5bee487c to your computer and use it in GitHub Desktop.
Y Combinator in C++20
#include <iostream>
int main() {
auto result = [](auto&& g) {
return [](auto&& f) {
return f(f);
}([&g](auto&& f) { return g([&f](auto&& x) { return f(f)(x); }); });
}([](auto&& f) {
return [&f](auto&& x) -> int { return x == 0 ? 1 : x * f(x - 1); };
})(5);
std::cout << result << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment