汉诺塔python实现

下载汉诺塔ppt

def move(n,A,B,C):
    if n == 1:
        print(A,'->',C)
    else:
        move(n-1,A,C,B)
        print(A,'->',C)
        move(n-1,B,A,C)

move(3,'A','B','C')

输出为:
A -> C
A -> B
C -> B
A -> C
B -> A
B -> C
A -> C

posted @ 2017-02-11 15:36  且如歌  阅读(1216)  评论(0编辑  收藏  举报
TOP