汉诺塔问题(递归)

博客地址:https://www.cnblogs.com/zylyehuo/

# _*_coding:utf-8_*_

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(5, 'A', 'B', 'C')

posted @ 2023-08-11 17:30  zylyehuo  阅读(7)  评论(0编辑  收藏  举报