Skip to content

Commit

Permalink
Merge pull request #1988 from codingCapricorn/master
Browse files Browse the repository at this point in the history
Create TowerOfHanoi.py
  • Loading branch information
geekcomputers authored Oct 7, 2023
2 parents d9186d2 + fd1fe56 commit b63e971
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions TowerOfHanoi.py
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 b63e971

Please sign in to comment.