Created
February 23, 2021 10:30
-
-
Save secf4ult/d6cd94ae3de06986cbe7fd430686e375 to your computer and use it in GitHub Desktop.
Ackermann Function
This file contains 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
#include <stdio.h> | |
int ack(int m, int n) | |
{ | |
int ans; | |
if (m == 0) ans = n + 1; | |
else if (n == 0) ans = ack(m - 1, 1); | |
else ans = ack(m - 1, ack(m, n - 1)); | |
return (ans); | |
} | |
int main (int argc, char ** argv) | |
{ | |
int i, j; | |
for (i = 0; i < 6; i++) | |
for (j = 0; j < 6; j++) | |
printf("ackerman (%d, %d) is: %d\n", i, j, ack(i, j)); | |
} |
This file contains 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
const ackmann = (m, n) => | |
m === 0 ? | |
n + 1 : | |
n === 0 ? | |
ackmann(m - 1, 1) : | |
ackmann(m - 1, ackmann(m, n - 1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment