Skip to content

Commit

Permalink
Create TowerOfHanoiTushar
Browse files Browse the repository at this point in the history
  • Loading branch information
Tushar-013 authored Oct 2, 2023
1 parent e438de5 commit f848fa1
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Add Code Here/PYTHON/TowerOfHanoiTushar
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Recursive Python function to solve the tower of hanoi

def TowerOfHanoi(n , source, destination, auxiliary):
if n==1:
print ("Move disk 1 from source",source,"to destination",destination)
return
TowerOfHanoi(n-1, source, auxiliary, destination)
print ("Move disk",n,"from source",source,"to destination",destination)
TowerOfHanoi(n-1, auxiliary, destination, source)

# Driver code
n = 4
TowerOfHanoi(n,'A','B','C')
# A, C, B are the name of rods

0 comments on commit f848fa1

Please sign in to comment.