Skip to content

Commit 2dd33df

Browse files
author
codehouseindia
authored
Merge pull request codehouseindia#509 from HarshithB/patch-4
Added TOH
2 parents 67a3b32 + a56946c commit 2dd33df

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

TOH.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# https://www.facebook.com/harsith.gayle.1/posts/2784315391846205
2+
# Subscribed by Code House
3+
4+
5+
6+
7+
# Recursive Python function to solve the tower of hanoi
8+
9+
def TowerOfHanoi(n , source, destination, auxiliary):
10+
if n==1:
11+
print "Move disk 1 from source",source,"to destination",destination
12+
return
13+
TowerOfHanoi(n-1, source, auxiliary, destination)
14+
print "Move disk",n,"from source",source,"to destination",destination
15+
TowerOfHanoi(n-1, auxiliary, destination, source)
16+
17+
# Driver code
18+
n = 4
19+
TowerOfHanoi(n,'A','B','C')

0 commit comments

Comments
 (0)