Skip to content

Instantly share code, notes, and snippets.

@ChristianSiegert
Created June 16, 2012 17:49
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ChristianSiegert/2942073 to your computer and use it in GitHub Desktop.
Solution written in Go for challenge 2012-05-25 on ProgrammingPraxis.com
package main
import (
"fmt"
)
func main() {
fmt.Println("Challenge from: http://programmingpraxis.com/2012/05/25/ackermanns-function/")
fmt.Println("Challenge: Your task is to implement Ackermann’s function.")
fmt.Println("A(3, 4):", A(3, 4))
}
// Ackermann function according to http://programmingpraxis.com/2012/05/25/ackermanns-function/
func A(m, n int) (result int) {
if m == 0 {
result = n + 1
} else if m > 0 && n == 0 {
result = A(m-1, 1)
} else if m > 0 && n > 0 {
result = A(m-1, A(m, n-1))
}
return
}
@ChristianSiegert
Copy link
Author

Console output:

$ go run challenge-2012-05-25.go 
Challenge from: http://programmingpraxis.com/2012/05/25/ackermanns-function/
Challenge: Your task is to implement Ackermann’s function.
A(3, 4): 125

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