首页 > 其他 > 详细

汉诺塔问题

时间:2021-08-19 10:10:55      阅读:27      评论:0      收藏:0      [点我收藏+]

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

  

汉诺塔问题

原文:https://www.cnblogs.com/ahao214/p/15159660.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!