-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e438de5
commit f848fa1
Showing
1 changed file
with
14 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |