MCPcopy Create free account
hub / github.com/geekcomputers/Python / TowerOfHanoi

Function TowerOfHanoi

Python Programs/Python Program for Tower of Hanoi.py:2–8  ·  view source on GitHub ↗
(n, source, destination, auxiliary)

Source from the content-addressed store, hash-verified

1# Recursive Python function to solve the tower of hanoi
2def TowerOfHanoi(n, source, destination, auxiliary):
3 if n == 1:
4 print("Move disk 1 from source ", source, " to destination ", destination)
5 return
6 TowerOfHanoi(n - 1, source, auxiliary, destination)
7 print("Move disk ", n, " from source ", source, " to destination ", destination)
8 TowerOfHanoi(n - 1, auxiliary, destination, source)
9
10
11n = 4

Calls

no outgoing calls

Tested by

no test coverage detected