Skip to content

Instantly share code, notes, and snippets.

@ajm113
Created June 13, 2016 01:33
Show Gist options
  • Save ajm113/a3a303533bce9f68a198030132bc922b to your computer and use it in GitHub Desktop.
Save ajm113/a3a303533bce9f68a198030132bc922b to your computer and use it in GitHub Desktop.
Ackermann Function In Go Lang
/**
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