Discuss / Python / 汉诺塔

汉诺塔

Topic source

岁益寒

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

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

    if n<=0 :

        print('参数不正确')

        return

    if n==1:

        print('{} -> {}'.format(a , c))

    else:

        move(n-1,a,c,b)

        print('{} -> {}'.format(a , c))

        move(n-1,b,a,c)


  • 1

Reply