Python3实现汉诺塔问题
分析
n个盘子的时候:
1、把n-1个盘子从A经过C移动到B
2、把第n个盘子从A移动到C
3、把n-1个盘子从B经过A移动到C
题解
def hanoi(n, a, b, c):
if n > 0:
hanoi(n - 1, a, c, b)
print("moving from %s to %s" % (a, c))
hanoi(n - 1, b, a, c)
标签:实现,题解,hanoi,汉诺塔,盘子,移动,Python3
来源: https://blog.csdn.net/weixin_49756466/article/details/122485276