8 queen/game of life
Ken Seehof
kens at sightreader.com
Fri Jun 16 02:38:42 EDT 2000
Oops I hit "Send" too soon. My code in the previous message is way bogus.
Your homework assignment, Zamri, is: What's wrong with [[0]*8]*8 ?
Hint: what does the multiply operator really do with a list?
root wrote:
> 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
>
--
Ken Seehof
kens at sightreader.com
starship.python.net/crew/seehof
Hi! I'm a .signature virus! copy me into your .signature file to help me spread!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: kens.vcf
Type: text/x-vcard
Size: 343 bytes
Desc: Card for Ken Seehof
URL: <http://mail.python.org/pipermail/python-list/attachments/20000615/4feee546/attachment.vcf>
More information about the Python-list
mailing list