append ( copy ( diffRS ) ) #show(stateVectorT) r_0 = r_1 = r_2 = minus = 0 plus = 0 stateFifos = stateFifos. et cetera example of stateFifos for rN=3 rings : ,], ,], ,], ,], \ ,],],],] ] example of StateVectorT which represents the increment decrement of each tower: """ stateVectorT = for s in range ( 1, len ( GlobalStateRegisterT ) ) : diffRS = vector ( GlobalStateRegisterT ) - vector ( GlobalStateRegisterT ) stateVectorT. append ( copy ( Re ) ) #print ("Move disk",n,"from rod",from_rod,"to rod",to_rod,Re ) TowerOfHanoi ( n - 1, aux_rod, to_rod, from_rod, Re ) def setStateFifos ( rN, GlobalStateRegisterT ) : """ the three towers are represented by three Fifos with first initial state :,],second state:,]. append ( copy ( Re ) ) #print( "Move disk 1 from rod",from_rod,"to rod",to_rod,Re) return TowerOfHanoi ( n - 1, from_rod, aux_rod, to_rod, Re ) Re -= 1 Re = 1 GlobalStateRegisterT. But after searching the web, the deepcopy() function has saved me a lot of headaches! what I call fifos are in fact LIFOS !!! """ # def myRandom ( k ) : return floor ( k * random ( ) ) def make_3xN_matrix ( k, N ) : return matrix ( ZZ, for peg in ( 1.3 ) ] ) """this function TowerOfHanoi(n, from_rod,to_rod,aux_rod,Re) was adapted from Source: (you do not have to reinvent the wheel every time!) Recursive Python function to solve tower of hanoi '0', '1', '2' are the name of rods (or pegs) Contributed By Harshit Agrawal, example for rN=n=3 rings of GlobalStateRegisterT list created: ,]""" def TowerOfHanoi ( n, from_rod, to_rod, aux_rod, Re ) : global GlobalStateRegisterT if n = 1 : Re -= 1 Re = 1 GlobalStateRegisterT. Because of the fact that I did not understand the problems of copy of list, when these lists include sublists !! I wondered even if I did not lose my head, so I did not understand what was happening -). polygon import polygon from copy import deepcopy """it took me several hours to understand the malfunctions of my Python program.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |