Skip to content

Instantly share code, notes, and snippets.

@nethershaw
Created February 4, 2017 03:24
Show Gist options
  • Select an option

  • Save nethershaw/26c3d8089e0acb35af4d0e46022c5f7c to your computer and use it in GitHub Desktop.

Select an option

Save nethershaw/26c3d8089e0acb35af4d0e46022c5f7c to your computer and use it in GitHub Desktop.
The Ackermann function (https://en.wikipedia.org/wiki/Ackermann_function) implemented in Scala.
class A(var m: Int, var n: Int)
object A {
def apply(m: Int, n: Int): Int =
if (m > 0 && n == 0) {
println(m, n)
A(m - 1, 1) }
else if (m > 0 && n > 0) {
println(m, n)
A(m - 1, A(m, n - 1))
}
else {
println(m, n)
n + 1
}
}
@nethershaw
Copy link
Author

Anyone intending to run this is well advised to use small input values.

Very small.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment