8 queen/game of life
Grant Edwards
nobody at nowhere.nohow
Sat Jun 17 13:07:33 EDT 2000
On Thu, 15 Jun 2000 10:44:03 +0800, root at sirius.ftsm.ukm.my <root at sirius.ftsm.ukm.my> wrote:
>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.
While sitting around waiting for a software test to fail (I
really hate the bugs that will only happen once every day or
two), I translated my 8-queens program from Scheme to Python:
<ftp://ftp.visi.com/users/grante/stuff/queens.py>
[If anybody knows how to avoid having to write the bitmap data
to a temp file and the reading it back in with the Button() call,
please let me know!]
>2. 8 non-attacking queen.
>
> use backtracking. the function call itself back. how to do recursive call
> in python?
Pretty much the same as most other procedural languages.
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?
Declare it global in your function:
def addqueen():
global queen_count
queen_count = queen_count + 1
if queen_count != 8:
addqueen()
else:
print result
queen_count = -1
addqueen()
--
Grant Edwards grante Yow! The PILLSBURY
at DOUGHBOY is CRYING for
visi.com an END to BURT REYNOLDS
movies!!
More information about the Python-list
mailing list