Skip to content

Commit 8b4eea6

Browse files
Create towerOfHoni.py
1 parent 4fcc45c commit 8b4eea6

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

towerOfHoni.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Recursive Code
2+
3+
def TowerOfHanoi(n , source, destination, auxiliary):
4+
if n==1:
5+
print ("Move disk 1 from source",source,"to destination",destination)
6+
return
7+
TowerOfHanoi(n-1, source, auxiliary, destination)
8+
print ("Move disk",n,"from source",source,"to destination",destination)
9+
TowerOfHanoi(n-1, auxiliary, destination, source)
10+
11+
#Test Input
12+
n = 4
13+
TowerOfHanoi(n,'A','B','C')
14+
# Consider A B and C as the names of rods
15+

0 commit comments

Comments
 (0)