Last active
November 1, 2025 12:50
-
-
Save juanfal/79ca4e73649a5a0b3fe3fd82923f3e4e to your computer and use it in GitHub Desktop.
Ackermann, heavily recursive function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ackerman.cpp | |
| // juanfc 2025-11-01 | |
| // ackermann(4, 0) -> 13 | |
| // ackermann(4, 1) -> 65533 | |
| // ackermann(4, 2) -> … 19,729 digits … | |
| // | |
| // https://gist.github.com/juanfal/79ca4e73649a5a0b3fe3fd82923f3e4e | |
| #include <iostream> | |
| using namespace std; | |
| int main() | |
| { | |
| int ackermann(int, int); | |
| int m, n; | |
| do { | |
| cout << "Introducir m y n: "; | |
| cin >> m >> n; | |
| cout << "ackermann(" << m << "," << n << "): " << ackermann(m, n) << endl; | |
| } while (m != 0 or n != 0); | |
| return 0; | |
| } | |
| int ackermann(int m, int n) | |
| { | |
| if (m == 0) | |
| return n+1; | |
| else if (n == 0) | |
| return ackermann(m-1, 1); | |
| else | |
| return ackermann(m-1, ackermann(m, n-1)); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ackermann.cpp | |
| // juanfc 2025-11-01 | |
| // ackermann(4, 0) -> 13 | |
| // ackermann(4, 1) -> 65533 | |
| // ackermann(4, 2) -> … 19,729 digits … | |
| // | |
| // https://gist.github.com/juanfal/79ca4e73649a5a0b3fe3fd82923f3e4e | |
| #include <iostream> | |
| using namespace std; | |
| int main() | |
| { | |
| int ackermann(int, int); | |
| int m, n; | |
| do { | |
| cout << "Introducir m y n: "; | |
| cin >> m >> n; | |
| cout << "ackermann(" << m << "," << n << "): " << ackermann(m, n) << endl; | |
| } while (m != 0 or n != 0); | |
| return 0; | |
| } | |
| int ackermann(int m, int n) | |
| { | |
| if (m == 0) | |
| return n+1; | |
| else if (n == 0) | |
| return ackermann(m-1, 1); | |
| else | |
| return ackermann(m-1, ackermann(m, n-1)); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment