Discuss / Python / 参考了https://www.zhihu.com/question/24385418/answer/252603808

参考了https://www.zhihu.com/question/24385418/answer/252603808

Topic source

def move(n, a, b, c):

    if n == 1:

        print(a, '-->', c)

    else:

        move(n-1, a, c, b) #将n-1个盘从A移至B,C为中转柱

        move(1, a, b, c) #将最大盘从A移至C

        move(n-1, b, a, c) #将n-1个盘从B移至C,A为中转柱

everyxy

#2 Created at ... [Delete] [Delete and Lock User]

很清晰


  • 1

Reply