MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / move_tower

Function move_tower

other/tower_of_hanoi.py:1–15  ·  view source on GitHub ↗

>>> move_tower(3, 'A', 'B', 'C') moving disk from A to B moving disk from A to C moving disk from B to C moving disk from A to B moving disk from C to A moving disk from C to B moving disk from A to B

(height, from_pole, to_pole, with_pole)

Source from the content-addressed store, hash-verified

1def move_tower(height, from_pole, to_pole, with_pole):
2 """
3 >>> move_tower(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 move_tower(height - 1, from_pole, with_pole, to_pole)
14 move_disk(from_pole, to_pole)
15 move_tower(height - 1, with_pole, to_pole, from_pole)
16
17
18def move_disk(fp, tp):

Callers 1

mainFunction · 0.85

Calls 1

move_diskFunction · 0.85

Tested by

no test coverage detected