Created
October 11, 2014 22:02
-
-
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
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.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