Skip to content

Instantly share code, notes, and snippets.

@raed667
Created October 11, 2014 22:02
Show Gist options
  • Save raed667/26763b6f41c9eb6734b3 to your computer and use it in GitHub Desktop.
Save raed667/26763b6f41c9eb6734b3 to your computer and use it in GitHub Desktop.
Simple recursive try to solve Hanoï in go. The output displays the steps and the total number of iterations
package main
import "fmt"
func main() {
fmt.Print("Number of iterations: " , move((uint64)(3), "1", "2", "3", (uint64)(0)))
}
func move(n uint64, a, b, c string,x uint64) uint64 {
if n > 0 {
x++
x=move(n-1, a, c, b,x)
fmt.Println("Moved from " + a + " to " + c)
x=move(n-1, b, a, c,x)
}
return x
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment