Skip to content

Commit 4f375ad

Browse files
authored
Merge pull request DeepNinja07x#105 from heny742/master
Create tower-of-hanoi.py
2 parents ad7f5c1 + 53b5de0 commit 4f375ad

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Algorithms/tower-of-hanoi.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Recursive Python function to solve the tower of hanoi
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+
# Driver code
12+
n = 4
13+
TowerOfHanoi(n,'A','B','C')
14+
# A, C, B are the name of rods

0 commit comments

Comments
 (0)