8 queen/game of life

Kevin Russell krussell4 at videon.home.com
Thu Jun 15 00:30:58 EDT 2000


root wrote:

>    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,....

If it works, then it IS the right way.  After all, there's more than one
way to... oops, sorry, wrong newsgroup.

As Trent Mick has pointed out, there's NumPy for doing serious
matrix manipulation.  But the demands of the Game of Life and the
8-Queens problem are minimal enough that a list-of-lists solution
or your dictionary solution are perfectly adequate.



>
> 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;

It's pretty straightforward to translate a standard backtracking
algorithm from practically any AI textbook into Python.  I tried it
out as an exercise when I was first learning Python, but the result
died in a disk crash.

You might want to look at Mark Lutz's Holmes -- a proof-of-
concept expert system shell in Python.  It illustrates a few different
backward chaining and forward chaining inference algorithms.

[Aside to peanut gallery:  Did the only web-accessible copy of
Holmes die in the Starship disk crash?  It seems to me to be
something worth having in the Vaults of Parnassus.  If Mark is
reading this, is willing to put it there, but is too busy, I'd be happy
to send them my own copy.]

And, with the advent of Stackless Python, the possibilities for doing
backtracking directly with continuations are just beginning.

Good luck.

-- Kevin





More information about the Python-list mailing list