Eight Queens Puzzle by Magnus Lie Hetland

Michael Surette msurette at myrealbox.com
Wed Aug 13 21:14:23 CEST 2003


On Wed, 13 Aug 2003 06:57:26 -0700, chansky wrote:

> I've been reading Magnus Lie Hetland's book, Practical Python. In one
> of the chapters he discusses how to use a Generator function to solve
> the Eight Queens puzzle. The following is part of his codes:

....
 
> I've a hard time to understand the following statement:
> 
> if abs(state[i]-nextX) in (0,nextY-i):
> 
> The author said that this statement will be True if the horizontal
> difference b/w the next queen and the previous one under consideration
> is euqal to zero or equal to the vertical distance (diagonally), and
> false otherwise.
> 
> Well, maybe I'm really slow. What does that "vertical distance" really
> mean? If someone out there has read his book, can you help me
> understand that line of code.

I haven't read the book, but I would suspect that the vertical distance is
the difference in the Y values of the two positions, just as the
horizontal distance is the difference in the X values.

hth
Mike




More information about the Python-list mailing list