#------------------------------------------------------------------------------- # TowersOfHanoi.py #------------------------------------------------------------------------------- def hanoi(n, i, j): """ Prints instructions for moving n discs from rod i to rod j, where n>=1, i, j in {1, 2, 3}, and i!=j. """ if n>0: k = 6-i-j # calculate the other rod number hanoi(n-1, i, k) print(i, "-->", j) hanoi(n-1, k, j) # end # if n==0 print nothing # end #------------------------------------------------------------------------------ if __name__=='__main__': # hanoi(5, 1, 3) # hanoi(4, 1, 3) hanoi(3, 1, 3); # hanoi(2, 1, 3) # hanoi(1, 1, 3) # hanoi(0, 1, 3)