python 汉诺塔

def hanoi(n, a, b, c):
    if n > 0:
        hanoi(n - 1, a, c, b)
        print('%s->%s' % (a, c))
        hanoi(n - 1, b, a, c)

hanoi(2, "A", "B", "C")

 

posted @ 2019-05-27 16:17  Mr_Smith  阅读(175)  评论(0编辑  收藏  举报