Skip to content

Instantly share code, notes, and snippets.

@MitchiLaser
Created March 6, 2024 10:06
Show Gist options
  • Save MitchiLaser/1420e173ec4827145f2dab04bab9006f to your computer and use it in GitHub Desktop.
Save MitchiLaser/1420e173ec4827145f2dab04bab9006f to your computer and use it in GitHub Desktop.
Recursive lambda calculating Fibonacci number in C++
#include <iostream>
#include <cstdlib>
int main( int argc, char* argv[]) {
typedef unsigned long long int num_type;
std::cout << [](auto lambda, num_type number) -> num_type { return lambda(lambda, number); } ([](auto lambda, num_type number) -> num_type { return number <= 2 ? num_type(1) : lambda(lambda, number-1) + lambda(lambda, number-2); }, std::atoi(argv[1])) << std::endl;
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment