汉诺塔问题

#汉诺塔问题
count=0
def hannuo(n,scr,dst,mid):
    global count
    if n==1:
        print("{}:{}->{}".format(1,scr,dst))
        count+=1
    else:
        hannuo(n-1,scr,mid,dst)
        print("{}:{}->{}".format(n,scr,dst))
        count+=1
        hannuo(n-1,mid,dst,scr)
hannuo(4,"a","b","c")
print(count)
            

  

posted @ 2020-03-30 21:28  sumuwwx  阅读(74)  评论(0编辑  收藏  举报