Skip to content

Commit 36530b9

Browse files
authored
Merge pull request #176 from MrGrayCode/tower-of-hanoir-python
Tower of hanoir python
2 parents d3f621a + c6970ac commit 36530b9

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ This repository contains examples of various algorithms written on different pro
2222
| [Merge Sort](https://en.wikipedia.org/wiki/Merge_sort) | [:octocat:](merge_sort/clang) | [:octocat:](merge_sort/cpp) | [:octocat:](merge_sort/java) | [:octocat:](merge_sort/Python) | |
2323
| [Insertion Sort](https://en.wikipedia.org/wiki/Insertion_sort) | | [:octocat:](insertion_sort/Cpp) | [:octocat:](insertion_sort/java)| | [:octocat:](insertion_sort/javascript)|
2424
| [Counting Sort](https://en.wikipedia.org/wiki/Counting_sort) | [:octocat:](counting_sort/clang) | [:octocat:](counting_sort/cpp) | [:octocat:](counting_sort/java) | [:octocat:](counting_sort/Python) | |
25+
| [Tower of Hanoi](https://en.wikipedia.org/wiki/Tower_of_Hanoi) | [:octocat:](towers_of_hanoi/clang) | | | [:octocat:](towers_of_hanoi/Python) | |
2526

2627
## Implemented Data Structures
2728

towers_of_hanoi/python/hanoi.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
def towerOfHanoi(numberOfDisks, fromRod, toRod, auxRod):
2+
if numberOfDisks == 1:
3+
print("Move {} from {} to {}".format(numberOfDisks,fromRod,toRod))
4+
return
5+
towerOfHanoi(numberOfDisks-1,fromRod,auxRod,toRod)
6+
print("Move {} from {} to {}".format(numberOfDisks,fromRod,toRod))
7+
towerOfHanoi(numberOfDisks-1,auxRod,toRod,fromRod)
8+
9+
if __name__ == "__main__":
10+
n = int(input("Enter number of disks: "))
11+
towerOfHanoi(n,'A','C','B')

0 commit comments

Comments
 (0)