自己编的汉诺塔游戏过程

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
def tower(a,b,c,n):
    if n==1:
        print "put 1 from b to a."
    elif n==2:
        print "put 1 from %r to %r." % (b,c)
        print "put 2 from %r to %r." % (b,a)
        print "put 1 from %r to %r." % (c,a)
    else:
        tower(c,b,a,n-1)
        print "put %d from %r to %r." % (n,b,a)
        tower(a,c,b,n-1)
         
def MITtower(a,b,c,n):
    if n==1:
        print "put", n, "from", b, "to", a
    else:
        MITtower(c,b,a,n-1)
        print "put",n,"from" ,b, "to" ,a
        MITtower(a,c,b,n-1)