Skip to content

Instantly share code, notes, and snippets.

@secf4ult
Created February 23, 2021 10:30
Show Gist options
  • Save secf4ult/d6cd94ae3de06986cbe7fd430686e375 to your computer and use it in GitHub Desktop.
Save secf4ult/d6cd94ae3de06986cbe7fd430686e375 to your computer and use it in GitHub Desktop.
Ackermann Function
#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));
}
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