Stu W
0
Q:

python tower of hanoi

# Recursive Python function to solve tower of hanoi 
  
def TowerOfHanoi(n , source, destination, auxilliary): 
    if n==1: 
        print "Move disk 1 from source",source,"to destination",destination 
        return
    TowerOfHanoi(n-1, source, auxilliary, destination) 
    print "Move disk",n,"from source",source,"to destination",destination 
    TowerOfHanoi(n-1, auxilliary, destination, source) 
          
# Driver code 
n = 4
TowerOfHanoi(n,'A','B','C')  
# A, C, B are the name of rods 
  
# Contributed By Dilip Jain 
1

New to Communities?

Join the community