其他分享
首页 > 其他分享> > 汉诺塔问题

汉诺塔问题

作者:互联网

移动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)

  

标签:柱子,hanoiAlgorithm,圆盘,问题,汉诺塔,print,移动
来源: https://www.cnblogs.com/ahao214/p/15159660.html