def move(n, a, b, c):
if n==1:
print('Move dish %s from %s to %s' % (n,a,c))
else:
move(n-1,a,c,b)
print('Move dish %s from %s to %s' % (n,a,c))
move(n-1,b,a,c)
move(3,'a','b','c')
Move dish 1 from a to c
Move dish 2 from a to b
Move dish 1 from c to b
Move dish 3 from a to c
Move dish 1 from b to a
Move dish 2 from b to c
Move dish 1 from a to c
大牛201601
def move(n, a, b, c): if n==1: print('Move dish %s from %s to %s' % (n,a,c)) else: move(n-1,a,c,b) print('Move dish %s from %s to %s' % (n,a,c)) move(n-1,b,a,c)
move(3,'a','b','c')
Move dish 1 from a to c Move dish 2 from a to b Move dish 1 from c to b Move dish 3 from a to c Move dish 1 from b to a Move dish 2 from b to c Move dish 1 from a to c