Skip to content

Instantly share code, notes, and snippets.

@camilajenny
Created December 20, 2017 07:20
Show Gist options
  • Save camilajenny/102d2d13a1b25cf8b1fce27029b80415 to your computer and use it in GitHub Desktop.
Save camilajenny/102d2d13a1b25cf8b1fce27029b80415 to your computer and use it in GitHub Desktop.
#include <cstdio>
#include <functional>
using namespace std;
int edgeOperation(int &n);
int productOperation(int &n);
const function<int(int &)> operations[2] = {&productOperation, &edgeOperation};
int edgeOperation(int &n) {
--n;
return (n + 1) * operations[!!n](n);
}
int productOperation(int &n) {
return 1;
}
int factorial(int n) {
return operations[!!n](n);
}
int main() {
printf("%d\n", factorial(10));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment