Created
June 13, 2016 01:33
-
-
Save ajm113/a3a303533bce9f68a198030132bc922b to your computer and use it in GitHub Desktop.
Ackermann Function In Go Lang
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
/** | |
Ackermann Function in Go! | |
@see https://en.wikipedia.org/wiki/Ackermann_function | |
@author Andrew McRobb | |
*/ | |
package main | |
import "fmt" | |
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)) | |
} | |
func main() { | |
for m := 0; m < 4; m++ { | |
for n := 0; n < 6; n++ { | |
var str string = fmt.Sprintf("A(%d, %d) = %d", m, n, ack(m, n)); | |
fmt.Println(str) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment