def hanoi(n, a, b, c):
"""
汉诺塔问题:
1.将n-1个盘子从a移动到c
2.将a剩下的一个盘子从a移动到c
3,将n-1个盘子从b经过a移动到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(3, "a", 'b', 'c')
标签:入门,递归,hanoi,算法,汉诺塔,print,moving,盘子,移动
来源: https://www.cnblogs.com/argos/p/14288480.html