Skip to content

Instantly share code, notes, and snippets.

@mormahr
Last active July 17, 2016 21:58
Show Gist options
  • Save mormahr/0b9cf26ecc62b286743ec5643286fb9f to your computer and use it in GitHub Desktop.
Save mormahr/0b9cf26ecc62b286743ec5643286fb9f to your computer and use it in GitHub Desktop.
#include <iostream>
#include <iomanip>
using namespace std;
int Ack(int n, int m) {
static int aufrufe = 0;
aufrufe++;
cout << "[" << setw(6) << aufrufe << ". Aufruf] " << "Ack(" << n << ", " << m << ")" << endl;
if (n == 0 && m >= 0) {
return m + 1;
} else if (n >= 1 && m == 0) {
return Ack(n - 1, 1);
} else if (n >= 1 && m >= 1) {
return Ack(n - 1, Ack(n, m - 1));
} else {
throw "Nicht definiert";
}
}
int main() {
cout << Ack(3, 4) << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment