def hanoi(n, a, b, c): if(n == 1): print(a, '-->', c) return hanoi(n - 1, a, c, b) print(a, '-->', c) hanoi(n - 1, b, a, c) # Output of hanoi(3, 'A', 'B', 'C'): # A --> C # A --> B # C --> B # A --> C # B --> A # B --> C # A --> C
原文地址:http://blog.csdn.net/troubleshooter/article/details/46623337