Discuss / Python / 我的答案

我的答案

Topic source
def move(n,a,b,c):
    if n==1:
        print("%s --> %s"%(a,c))#the basic situation
    else:
        move(n-1,a,c,b)#move the n-1 from a to b
        move(1,a,b,c)#now,a has just one dish,so just move it to c
        move(n-1,b,a,c)#now,move the n-1 dishes from b to c

if __name__ == '__main__':
    move(3,"A","B","C")

  • 1

Reply