汉诺塔

count=0
def hanoi(n,A,C,B):
global count
if n==1:
print("{}:{}->{}".format(1,A,C))
count+=1
else:
hanoi(n-1,A,B,C)
print("{}:{}->{}".format(1,A,C))
count+=1
hanoi(n-1,B,C,A)
hanoi(3,'A','C','B')
print(count)

posted @ 2020-03-29 21:28  Lysim  阅读(89)  评论(0)    收藏  举报