• 周六. 4月 27th, 2024

5G编程聚合网

5G时代下一个聚合的编程学习网

热门标签

汉诺塔问题

admin

11月 28, 2021

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

  

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注