# Category : Files from Magazines

Archive : ITP9004.ZIP

Filename : QUEEN1.PAS

* QUEEN1 - the first attempt at solving the *

* queens problem. *

* *

* INP: c - the column # to place a queen in *

* n - the maximum column (& row) number *

* USES: Soln - updates this solution counter *

* whenever a queen is successfully placed *

* in the n'th column. *

************************************************}

UNIT Queen1;

INTERFACE

CONST

MaxBrd = 25;

VAR

{Chess brd}

Board : ARRAY[0..MaxBrd+1,0..MaxBrd+1] OF Byte;

Solns : Integer;

PROCEDURE InitBoard;

PROCEDURE Queens(C,N: Integer);

IMPLEMENTATION

PROCEDURE InitBoard;

BEGIN

FillChar(Board,SizeOf(Board),#0);

Solns := 0

END;

PROCEDURE Queens;

VAR

I,J : Integer;

Legal : Boolean;

BEGIN

{Have we found a solution?}

IF C=N THEN

Inc(Solns)

ELSE

{Check each spot in the column}

BEGIN

FOR I:= 0 TO N-1 DO

BEGIN

Legal := TRUE; {Legal until disproven}

FOR J := 1 TO C DO

BEGIN

{-- Check row --}

IF (Board[I,C-J] <> 0) THEN

Legal := FALSE;

{-- Check diagonal 1 --}

IF ((I+J) < N) THEN

IF (Board[I+J,C-J] <> 0) THEN

Legal := FALSE;

{-- Check diagonal 2 --}

IF ((I-J) >= 0) THEN

IF (Board[I-J,C-J] <> 0) THEN

Legal := FALSE;

END;

IF (Legal) THEN

BEGIN

Board[I,C] := 1; {Put queen here}

Queens(C+1,N); {Process next col}

Board[I,C] := 0 {Remove & try next}

END;

END;

END;

END;

END.

Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/