# -*- coding: UTF-8 -*-
def move(n, a, b, c):
if n==1:
print a,'-->',c
else:
move(n-1,a,c,b)#把a盘前面n-1个盘子借助c实现a盘移到b盘
print a,'-->',c#把a盘最后一个盘子放到c
move(n-1,b,a,c)#把b盘的n-1个盘子借助a盘移到c盘
move(4, 'A', 'B', 'C')
运行结果:
A --> B
A --> C
B --> C
A --> B
C --> A
C --> B
A --> B
A --> C
B --> C
B --> A
C --> A
B --> C
A --> B
A --> C
B --> C