Skip to content

Instantly share code, notes, and snippets.

@oliverbooth
Created June 16, 2017 23:22
Show Gist options
  • Save oliverbooth/9c7fd67105663bb962b94f9fa2dc7b29 to your computer and use it in GitHub Desktop.
Save oliverbooth/9c7fd67105663bb962b94f9fa2dc7b29 to your computer and use it in GitHub Desktop.
/// <summary>
/// Calculates the Ackerman function for two values.
/// </summary>
/// <param name="m">The first value.</param>
/// <param name="n">The second value.</param>
/// <returns>Returns the result of the Ackerman function.</returns>
int Ackerman(int m, int n)
{
if (m == 0)
{
return n + 1;
}
else if (n == 0)
{
return Ackerman(m - 1, 1);
}
else
{
return Ackerman(m - 1, Ackerman(m, n - 1));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment