Golang Source Code
/* Author: Hannes du Plooy */
/* Date: 20 Sep 2016 */
/* Objective: To solve the towers of hanoi with number of discs provided in the arguments to calling the program */
package main
import (
"fmt"
"os"
"strconv"
)
func hanoi(source,dest,other,discs int) {
if (discs > 0) {
hanoi(source,other,dest,discs-1)
fmt.Printf("Move %d to %d\n",source,dest)
hanoi(other,dest,source,discs-1)
}
}
func main() {
if len(os.Args) < 2 {
fmt.Println("Please provide number of discs!")
} else {
discs, _ := strconv.Atoi(os.Args[1])
hanoi(0,2,1,discs)
}
}