Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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

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
Something went wrong with that request. Please try again.