Created
February 4, 2017 03:24
-
-
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.
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
| 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 | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Anyone intending to run this is well advised to use small input values.
Very small.