Last active
August 29, 2015 14:17
-
-
Save alecthegeek/cfaefb9146193ec3ac68 to your computer and use it in GitHub Desktop.
Simple Ackermann function
This file contains hidden or 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
// Niave implementation of the Ackermann function | |
// https://en.wikipedia.org/wiki/Ackermann_function | |
package main | |
import "fmt" | |
func Ackermann(m, n uint) uint { | |
//fmt.Printf("Called Ackermann(%d,%d) ", m, n) | |
if m == 0 { | |
return n + 1 | |
} | |
if n == 0 { | |
return Ackermann(m-1, 1) | |
} | |
return Ackermann(m-1, Ackermann(m, n-1)) | |
} | |
func main() { | |
// Will stop at Ackermann(4,1) because Ackerman(4,2) is 10^19728.30179583443 | |
// see http://m.wolframalpha.com/input/?i=what+is+ackermann+4%2C2%3F&x=0&y=0 | |
for i := uint(0); i < 5; i++ { | |
for j := uint(0); j < 2; j++ { | |
fmt.Printf("Ackermann of %d %d is %d\n", i, j, Ackermann(i, j)) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment