Last active
August 29, 2015 14:01
-
-
Save tinylamb/7d9c07acdf8549e66055 to your computer and use it in GitHub Desktop.
Introduction to Computer Science and Programming[Mit]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#汉诺塔 | |
#Towers(3,0,1,2) | |
def Towers(size,fromStack,toStack,spareStack): | |
if size == 1: | |
print 'Move disk from ',fromStack, 'to ',toStack | |
else: | |
Towers(size-1,fromStack,spareStack,toStack) #将n-1个盘子从起点移到空闲 | |
Towers(1,fromStack,toStack,spareStack) #将最大的盘子从起点移到终点 | |
Towers(size-1,spareStack,toStack,fromStack) #将n-1个盘子从空闲移到终点 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment