汉诺塔问题

移动n个圆盘
1、把n-1个圆盘从A柱子经过C柱子移动到B柱子
2、把第n个圆盘从A柱子移动到C柱子
3、把n-1个圆盘从B柱子经过A柱子移动到C柱子

def hanoiAlgorithm(n, a, b, c):
    if n > 0:
        hanoiAlgorithm(n - 1, a, c, b)
        print("moving from %s to %s" % (a, c))
        hanoiAlgorithm(n - 1, b, a, c)

  

posted @ 2021-08-19 06:49  算盘  阅读(61)  评论(0编辑  收藏  举报