Skip to content

Commit 45af05b

Browse files
committed
improvement
1 parent 8d5be8a commit 45af05b

File tree

2 files changed

+25
-33
lines changed

2 files changed

+25
-33
lines changed

Tower_of_Hanoi.py

-33
This file was deleted.

other/tower_of_hanoi.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
def moveTower(height, fromPole, toPole, withPole):
2+
'''
3+
>>> moveTower(3, 'A', 'B', 'C')
4+
moving disk from A to B
5+
moving disk from A to C
6+
moving disk from B to C
7+
moving disk from A to B
8+
moving disk from C to A
9+
moving disk from C to B
10+
moving disk from A to B
11+
'''
12+
if height >= 1:
13+
moveTower(height-1, fromPole, withPole, toPole)
14+
moveDisk(fromPole, toPole)
15+
moveTower(height-1, withPole, toPole, fromPole)
16+
17+
def moveDisk(fp,tp):
18+
print('moving disk from', fp, 'to', tp)
19+
20+
def main():
21+
height = int(input('Height of hanoi: '))
22+
moveTower(height, 'A', 'B', 'C')
23+
24+
if __name__ == '__main__':
25+
main()

0 commit comments

Comments
 (0)