汉诺塔实现

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

# -*- coding: utf-8 -*-


def move(n, A, B, C):
	if n <= 0:
		return

	if n == 1:
		print('move', A, '#1--------->', C)
		return

	if n == 2:
		print('move', A, '#1--------->', B)
		print('move', A, '#2--------->', C)
		print('move', B, '#1--------->', C)
		return

	move(n-1, A, C, B)
	print('move', A, '#%d'%n, '-------->', C)
	move(n-1, B, A, C)


move(5, 'A', 'B', 'C')