MCPcopy Create free account
hub / github.com/Jack-Lee-Hiter/AlgorithmsByPython / Hanoi

Function Hanoi

Recursion.py:30–36  ·  view source on GitHub ↗
(fromPole, withPole, toPole, diskNum)

Source from the content-addressed store, hash-verified

28
29# 递归实现Hanoi塔
30def Hanoi(fromPole, withPole, toPole, diskNum):
31 if diskNum <= 1:
32 print("moving disk from %s to %s" % (fromPole, toPole))
33 else:
34 Hanoi(fromPole, toPole, withPole, diskNum-1)
35 print("moving disk from %s to %s" % (fromPole, toPole))
36 Hanoi(withPole, fromPole, toPole, diskNum-1)
37
38Hanoi('A', 'B', 'C', 3)

Callers 1

Recursion.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected