Created
January 8, 2022 18:06
-
-
Save proxpero/dc99c6971fe4656bb88eabb0f3c05418 to your computer and use it in GitHub Desktop.
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
public func ack(_ m: Int, _ n: Int) -> Int { | |
if m == 0 { return n + 1 } | |
if n == 0 { return ack(m - 1, 1) } | |
return ack(m - 1, ack(m, n - 1)) | |
} | |
for i in (0...5) { | |
for j in (0...5) { | |
print("ack(\(i), \(j)) is \(ack(i, j))") | |
} | |
} | |
/* | |
result: | |
ack(0, 0) is 1 | |
ack(0, 1) is 2 | |
ack(0, 2) is 3 | |
ack(0, 3) is 4 | |
ack(0, 4) is 5 | |
ack(0, 5) is 6 | |
ack(1, 0) is 2 | |
ack(1, 1) is 3 | |
ack(1, 2) is 4 | |
ack(1, 3) is 5 | |
ack(1, 4) is 6 | |
ack(1, 5) is 7 | |
ack(2, 0) is 3 | |
ack(2, 1) is 5 | |
ack(2, 2) is 7 | |
ack(2, 3) is 9 | |
ack(2, 4) is 11 | |
ack(2, 5) is 13 | |
ack(3, 0) is 5 | |
ack(3, 1) is 13 | |
ack(3, 2) is 29 | |
ack(3, 3) is 61 | |
ack(3, 4) is 125 | |
ack(3, 5) is 253 | |
ack(4, 0) is 13 | |
ack(4, 1) is 65533 | |
Program ended with exit code: 11 <- kaboom! ack(4, 2) is already too big | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment