(fromPole, withPole, toPole, diskNum)
| 28 | |
| 29 | # 递归实现Hanoi塔 |
| 30 | def 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 | |
| 38 | Hanoi('A', 'B', 'C', 3) |