def tower(height,fromtw,totw,midtw):
if height==1:
print"{}-->{}".format(fromtw,totw)
else:
tower(height-1,fromtw,midtw,totw)
print“{}-->{}”.format(fromtw,totw)
tower(height-1,midtw,totw,fromtw)
tower(2,"A","B","C")
A-->C
A-->B
C-->B
def tower(height,fromtw,totw,midtw):
if height==1:
print"{}-->{}".format(fromtw,totw)
else:
tower(height-1,fromtw,midtw,totw)
print“{}-->{}”.format(fromtw,totw)
tower(height-1,midtw,totw,fromtw)
tower(2,"A","B","C")
A-->C
A-->B
C-->B
本文标题:河内塔问题
本文链接:https://www.haomeiwen.com/subject/cliohxtx.html
网友评论