Python - 汉诺塔
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
posted on 2017-05-24 13:13 cynchanpin 阅读(231) 评论(0) 编辑 收藏 举报