Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def ToH(sourcen,destn,sparen,n,source=None,destination=None, spare=None,printer=None):
- if source == None:
- source = range(1,n+1)[::-1]
- destination = []
- spare = []
- printer = []
- if n==1:
- printer.append( "Move disk" + str(source[-1]) + " from " + str(sourcen) + " to " + str(destn))
- #print len(printer)
- destination.append(source.pop())
- else:
- printer += ToH(sourcen,sparen,destn,(n-1),source,spare,destination,printer)
- printer += ToH(sourcen,destn,sparen,1,source,destination,spare,printer)
- printer += ToH(sparen,destn,sourcen,(n-1),spare, destination, source,printer)
- if len(printer)>100:
- print "!!"
- print printer[99]
- print ""
- raise("Problem")
- return printer
- print "starting..."
- ToH("A","B","C",13)
Advertisement
Add Comment
Please, Sign In to add comment