8 queen/game of life

root root at sirius.ftsm.ukm.my
Wed Jun 14 22:44:03 EDT 2000


newbie question.

has anyone wrote the 8 non-attacking queen problem and conway's game of life
in python? i try but face a few newbie problems.

1. conway's game of life:
   how to have a matrix in python? 
   the following is not good;
   
           r0=[0,0,0]
	   r1=[0,0,0]
	   ........
	   
	   m=[r0,r1,....]

   the matrix is fixed, which is not good. my solution use dictionary (i
   know this is not the right way). the key is a tuple of the matrix
   indices. the value is '0'. then base on game of life rule, update the
   dictionary and print for next generation.

	   m={}
	   m[(0,0)] = 0, m[(0,1)] = 1,....
	   
2. 8 non-attacking queen.

   use backtracking. the function call itself back. how to do recursive call
   in python? roughly, the C program I study look like this;
   
   queen_count = -1
   
   main()
   {
     addqueen();
   }
   
   addqueen()
   {
   queen_count++
   if queen_count != 8
        addqueen()
   else
        print result
   }
	
   how to pass a global variable (queen_count) to a function?
   
many thanks in advance.

zamri
   




More information about the Python-list mailing list