Solution written in Go for challenge 2012-05-25 on ProgrammingPraxis.com
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
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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Console output: