Large algorithm issue -- 5x5 grid, need to fit 5 queens plus some squares

Ben Cartwright bencvt at gmail.com
Thu Mar 16 06:12:53 CET 2006


totalgeekdom at gmail.com wrote:
> The first named clearbrd() which takes no variables, and will reset the
> board to the 'no-queen' position.
(snip)
> The Code:
> #!/usr/bin/env python
> brd = [9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
> def clearbrd():
> 	brd = [9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]

clearbrd() isn't doing what you want it to.  It should be written as:

  def clearbrd():
      global brd
      brd = [9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]

Explanation:
http://www.python.org/doc/faq/programming/#how-do-you-set-a-global-variable-in-a-function

--Ben




More information about the Python-list mailing list