a note on the queen's problem

8
Information Processing Letters 23 (1986) 39-46 North-Holland 20 July 1986 A NOTE ON THE QUEENS' PROBLEM Bernd-Ji~rgen FALKOWSKI and Lothar SCHMITZ Fakultiit fftr Informatik, Universitiit der Bundeswehr M~nchen, Werner-Heisenberg-Weg 39, D-8014 Neubiber~ Fed. Rep. Germany Communicated by H.R. Wiehle Received 31 May 1985 Revised 15 July 1985 and 18 August 1985 Keywords: Backtrack algorithms, queens' problem, permutations Introduction Ever since Gauss (cf. [1]), the problem of placing eight queens on a chessboard in such a way that no queen is attacking any other queen has attracted attention. However, even the great Gauss seems to have encountered some difficulties in finding all 92 solutions. In 1901, Netto [4] discussed the obvious generalization to n queens. In 1965, this problem occurs again [2] to illustrate the use of backtrack algorithms. Recently, it has become one of the favorite examples of the protagonists of structured programming and is thus known to almost any student of computer science (probably the most efficient backtrack algorithm currently known for the queens' problem may be found in [3]). Nevertheless, some rather strange and interesting features remain. (a) According to [4] as well as [5], a general analysis of the problem is not known. (b) For n = 5 there are two essentially different solutions whilst for n = 6 there is only one such solution. Thereafter, the number of solutions appears to increase with n. (c) To our knowledge, even the existence of a solution for arbitrary n has not been established. In this note we show how to construct a solution for arbitrary n > 3. Moreover, we find (cf. (b) above) that for n = 9 rood 12 the number of solutions increases at least linearly with n. We relied on computer experiments (using a backtrack algorithm) to find solutions for reasonably sized n. Thus, it became possible to look for certain solution patterns. Indeed, some patterns emerged which to our mind also seemed to be very pretty from an aesthetic point of view. We could then verify analytically that we had in fact obtained a solution. So, the interplay between using a computer on the one hand and relying on mathematical intuition on the other hand proved successful and led to results which could hardly have been established (cf. the opening remarks above) by hand calculation. 1. Description of the solution patterns In contrast to a classical chessboard we number rows and columns from 1 to n as shown in Fig. 1. It is immediately obvious (by considering horizontal and vertical threats) that to obtain a solution we must have precisely one queen in each row and precisely one queen in each column of the board. Moreover, two queens placed at points (i, j) and (k, ~) do not attack each other along a diagonal iff i+j~k+¢ and i-j~k-¢. 0020-0190/86/$3.50 © 1986, Elsevier Science Publishers B.V. (North-Holland) 39

Upload: bernd-juergen-falkowski

Post on 26-Aug-2016

216 views

Category:

Documents


3 download

TRANSCRIPT

Information Processing Letters 23 (1986) 39-46 North-Holland

20 July 1986

A N O T E ON T H E QUEENS ' P R O B L E M

Bernd-Ji~rgen FA LK OW SK I and Lothar SCHMITZ

Fakultiit fftr Informatik, Universitiit der Bundeswehr M~nchen, Werner-Heisenberg-Weg 39, D-8014 Neubiber~ Fed. Rep. Germany

Communicated by H.R. Wiehle Received 31 May 1985 Revised 15 July 1985 and 18 August 1985

Keywords: Backtrack algorithms, queens' problem, permutations

Introduction

Ever since Gauss (cf. [1]), the problem of placing eight queens on a chessboard in such a way that no queen is attacking any other queen has attracted attention. However, even the great Gauss seems to have encountered some difficulties in finding all 92 solutions. In 1901, Netto [4] discussed the obvious generalization to n queens. In 1965, this problem occurs again [2] to illustrate the use of backtrack algorithms. Recently, it has become one of the favorite examples of the protagonists of structured programming and is thus known to almost any student of computer science (probably the most efficient backtrack algorithm currently known for the queens' problem may be found in [3]). Nevertheless, some rather strange and interesting features remain.

(a) According to [4] as well as [5], a general analysis of the problem is not known. (b) For n = 5 there are two essentially different solutions whilst for n = 6 there is only one such

solution. Thereafter, the number o f solutions appears to increase with n. (c) To our knowledge, even the existence of a solution for arbitrary n has not been established. In this note we show how to construct a solution for arbitrary n > 3. Moreover, we find (cf. (b) above)

that for n = 9 rood 12 the number of solutions increases at least linearly with n. We relied on computer experiments (using a backtrack algorithm) to find solutions for reasonably sized

n. Thus, it became possible to look for certain solution patterns. Indeed, some pat terns emerged which to our mind also seemed to be very pret ty from an aesthetic point of view. We could then verify analytically that we had in fact obtained a solution. So, the interplay between using a computer on the one hand and relying on mathematical intuition on the other hand proved successful and led to results which could hardly have been established (cf. the opening remarks above) by hand calculation.

1. Description of the solution patterns

In contrast to a classical chessboard we number rows and columns from 1 to n as shown in Fig. 1. It is immediately obvious (by considering horizontal and vertical threats) that to obtain a solution we must have precisely one queen in each row and precisely one queen in each column of the board. Moreover, two queens placed at points (i, j) and (k, ~ ) do not attack each other along a diagonal iff

i + j ~ k + ¢ and i - j ~ k - ¢ .

0020-0190/86/$3.50 © 1986, Elsevier Science Publishers B.V. (North-Holland) 39

V o l u m e 23, N u m b e r 1

t)

] - - - . . . . - n

Fig. 1.

I N F O R M A T I O N P R O C E S S I N G L E T T E R S 20 Ju ly 1986

Equivalently, we may describe a solution by giving a permutation

1 . . . n )

a 1 . . . a n

satisfying lai - aj I ~ ]i - J l where (i, ai) are the coordinates of the ith queen. We do, however, wish to appeal to visual intuition. Thus, we are going to give diagrams in order to illustrate the idea of the solution before writing down the explicit formulas. The verification of the consistency conditions is omitted (it is lengthy but straightforward) with the exception of one representative case.

In order to give a solution for every n > 3 we need five different solution patterns, denoted by (A), (B), (C), (D), and (E). The equations below show that indeed all possibilities for n > 3 are exhausted and also which solution pattern applies to which n.

{ n ~ N I n > 3 } = { 6 x k + a l k E l ~ i A a ~ { - 2 , - 1 , 0 , 1 , 2 , 3 } }

= {6 x k + 21k GIN} U (6 x k + 3lk ~ N }

u ( 6 × k + a [ k ~ N A a ~ { - 2 , - 1 , 0 , 1 } } ,

"(A)"

{ 6 x k + 2 1 k ~ N } = { 6 x 2 x k + 2 1 k ~ N } td { 6 x ( 2 k - 1 ) + 2 1 k ~ N } ,

• ' (c) . . . . (B)"

( 6 × k + 3 1 k ~ N } = ( 6 × 2 × k + 3 1 k ~ N } u ( 6 × ( 2 k - 1 ) + 3 1 k ~ } ,

"(c)"

{6× ( 2 k - 1) + 3 1 k ~ N } = (12 × k - 3 1 k ~ N }

= ( 1 2 X 2 × k - 3 1 k ~ N } U { 1 2 x ( 2 k - 1 ) - 3 1 k ~ N }.

" ( E ) . . . . ( D ) "

(A) Solutions for n ~ {6 × k + a Ik ~ N ^ a ~ ( - 2 , - 1 , 0, 1}}

If n = 6k, 6k - 2, k = 1, 2 . . . . . then the location of the queens is described by the two sets of points (in the format (column, row))

A1 := {(2i, i) I1 ~< i ~< ½n}, A2 := { ( 2 i - 1, ½n + i) I1 ~< i~< ½n }

(see Fig. 2). Moreover, a solution for n = 6k - 1, 6k + 1, k = 1, 2, . . . , is obtained by 'adjoining' a queen in the top

right-hand corner since the diagonal from the bottom left-hand corner to the top right-hand corner is free (see Fig. 3).

40

Volume 23, Number 1 INFORMATION PROCESSING LETTERS

n=4 n=6 A2

A 2 " ~ A I ~ A 1

Fig. 2.

20 July 1986

Notice that the sets A i consist of a sequence of 'Knight's moves' and that the adjoined queens extend A 2 in a natural way.

(B) Solution for n E {12 × k - 4 Ik ~ N)

Here, the location of the queens is described by the four sets of points

BI:= ((2i, i + 1) 11 ~<i~ ½n},

B2 := {(4i + 3, ½n+ 2( i+ 1)10 ~ i ~ ¼(n - 4)},

B3 := {(4i + 1, ½n+ 2( i+ 1 )+ 1) 10 ~<i~ ¼(n- 8)},

B4:= ( ( n - 3, 1)}

(see Fig. 4). Notice that B 1 consists again of a sequence of 'Knight's moves', whilst B 2 and B 3 may be thought of as

a sequence of 'generalized Knight's moves'. (Similar observations hold in cases (C), (D), (E) below!)

(C) Solution for n ~ {12 × k + 2 Ik ~ N} u {12 × k + 3 Ik ~ N}

For n ~ {12 × k + 2 [k ~ N), the location of the queens is described by the four sets

C1:= {(2i, i + 1) 11 ~<i~< ½n),

C2:= {(4i+ 3, ½n+ 2(i+ 1)) 10 ~<i ~< ¼(n - 6)},

C3:= ( ( 4 i+ 1, ½n+ 2(i+ 1 )+ 1) 10 ~< i~< ¼(n- 6)},

C4:= ( (n - 1, I) }

(see Fig . 5). ( N o t e t h e a n a l o g y to case (B).)

n:5 n=7

: _ i_ ' . _ : [ e l ! _ : _ ! Q : _ : _ : ! Q : _ : _ ! _ ! _ : I _ : _ , . _ ! Q : _ : '._ : ¢ . '_ !_ :_ :

Fig. 3.

!__!__!__!__£__!__!Q: !__ !__!__!__!Q!__!__! :__ !__!g[__!__!__!__[ .* 0 !__!__!__!__ !__!__ ! !__ !__ !__!__!__! :~1__ ! '__!__!__! Q ! _ ! _ ! _ : ; _ ! C ! _ ! . ! _ ! _ ! _ !

41

Volume 23, Number 1 INFORMATION PROCESSING LETTERS

n=20

20 July 1986

B 3

Fig. 4.

'-.-'1'1'-;1'1;-_'-.'-;3~~ ~"- - - ' -~ B,, :_ :_ :_,._ :_ :_:_ :_,._ :_ , . ~ _ : a~ ' .~_ ._,._ :_ , . j r_: c : - : - '-- : - : - : - : - : - - ~ - : Q ' - - ' - t ~ - - - :. : | | I I I I | I l | I | |--I--I

I I I I I | t | | I I l U l I l - - I

• , ; - ; ' ; - " , - ; - ; - ; - ; - ; - ; - ; - , - ; - ; - ; ' I | l--I I ~1~| | l°|~O~ |--I |°l--|--l--|--

• __. .~. . o ° • . ° o . . . ° ° o o .

I l I | I $ l' | | l I l--I |--I--I

B ~ , , , , , , , , , , , , ;,.-,i..Z<e..,_ ~.,_>.._.-,~_-;

I

' - " ' - ' - ' - ' - ' - ' - ' - ' ~ ~ ' - _ - ' 3

,,:,,_- i- :,-,,- i-,,- :- !_-.,,_-! , ,-,ii iiiii!i?i?i!i

I I l--l-- I I-- I" I--I "I --l--l-- I--I-- I--I

I l I--l--I--l--I I I I l I l l I

, ;- ; - ; - ;- 2- ;- ;- ;-,'- ;- ',- ; ~ - . . . . B 4

The solution for n ~ {12 × k + 3 Ik ~ ~} is obtained by 'adjoining' a queen in the top left-hand comer. Note that this transforms the sets C1, C 2, C3, C 4 into the sets C~, C~, C~, C~ given below (see also Fig. 6):

C~ : : {(2i + 1, i+ 1) 11 ~<i~< ½(n-1 )} ,

C~ := { (4i + 4, ½(n - 1) + 2(i + 1))IO ~< i ~< ~(n - 7) },

C;:= { (4 i+ 2, ½ ( n - 1 ) + 2( i+ 1) + 1)10~<i~< ¼(n- 7)}, c~:: { (n- I, 1)}.

n=14

C3 ~ C2

~- ci

. . . . . . . . . . . . . . . . _ . . . . . . c 4 Fig. 5.

42

Volume 23, Number 1 INFORMATION PROCESSING LETTERS 20 July 1986

n = 1 5

! l J ! _ ! _ l _ ! _ l _ ! _ l _ ! _ l _ ! _ ! _ ! _ l I _ ! l _ l _ l _ l _ l _ l _ l . l _ l _ ! l l l _ l _ ! _ l _ ! _ ! ! _ ! _ ! _ ! _ l _ ! _ l _ l _ ! _ ! _ ! _ I O l _ ! _ ! _ I I _ I _ ! _ I _ I _ I I ! _ I _ I _ I _ I _ I _ I _ I _ I _ ! I _ I I _ I _ I _ ! _ ! _ I 0 ! _ I _ I . ! _ ! _ I _ ! _ ! l _ l l l _ l _ l _ l _ l . l _ l _ l _ l _ l . l _ l _ !_ I ! _ l _ l _ ! i ! _ l _ ! _ ! _ ! _ l _ ! _ l _ ! _ ! _ ! _ l ! _ ! . I _ I _ ! _ ! _ ! _ ! _ ! _ I _ ! _ ! _ ! _ !_!O I ! _ ! _ ! _ I _ ! _ I _ I _ I _ ! _ l _ l _ !_ l i ! _ ! _ l I I_ ! I _ ! I _ I _ I _ ! _ I _ I Q ! ! _ ! _ ! _ ! I _ I _ I _ I _ I _ I _ I _ I _ I @ I _ I _ I _ I _ ! _ I _ I ! _ I _ I _ I _ ! _ ! _ ! 01_ I_ ! _ I _ ! _ I _ I . !_ I I_ I _ I _ I _ I I I I _ I _ I _ ! _ I _ I _ I _ I _ I_ !_ I I _ I _ I 0 1 _ I _ I _ ! _ I _ I _ I _ I _ I _ I . ! _ ! _ l I _ I _ I _ I _ I . I _ I _ I _ I _ I _ I _ I I _ I 0 ! _ !

Fig. 6.

(D) Solution for n ~ { 24 × k - 15 I k ~ N }

Here, the location of the queens is described by the five sets

D 1 := { (2i + 1, ¼(3n + 1) - i)10 ~ i ~< ½(n - 1) },

D 2:= {(4i, ¼(n- 1 ) - 2 ( i - 1))11 ~<i~< ~ ( n - 1)},

D 3:= {(4i, n - 2 ( i - - ~ ( n + 7 ) ) ) I~ (n+ 7) ~<i~< ¼(n- 1)},

D 4:= {(4i+ 2, ¼(n- 5 ) - 2 i )10~i~<-~(n- 9)},

D s:= ( (4 i+ 2, n - 1 - 2 ( i - l ( n - 1)) ) I -~(n- 1) ~i~< ¼(n- 5)}

(see Fig. 7).

n=33 D 3

a - o - o - o - a - e - o - a - o - o - g - o - o - o - o - ! . . . . I - o - o - e - o - e - e - i - o - o ' e - o ; -'- ;-;-'-;-;-;-;- ;-;- ;-'- ;- ;- ;-~,' ~ i ; - ; - ; - ; - ;-;-;-;-; ; - , - : - ; - , - ; - ; - ; - ; - ; - ; - ; - ; - ; - ; - ; - , - . ~ , - , , " - ; - ; - ; - ; - , - ; - ; - ; e - - e - - e - - I - I - - | - - e - - e - i - - o - - m - - e " 1 - e - e " e - e - - i " l - ~ - i e " - - I - e - - e - - l ' o - e

e | | o o i I i o i | o e ~ m i e | o ! e i i e t e i l

' - :-'_-'_"_"-._-'_',- :_-:_- : - , - : - , - :_'!:! . . . . . . . . . . . . . . . . -., i i e o a I i i i i o o o o o o a o a a o o o o o a i

. . . . . . . . . . . . . o ! .a ! ! j ! ! t o J o o o o o ~ o o o o ~ o o o i . . . . . . . . . . . . . . . . . . . . . . . ~ - - - ' - . ' _ ' _ ' _ ; _ ' _ ; _ . _ ~ _ . _ : _ : 5

i i ! q t o i o o e I o t a a I g ~ q I ~ a o | o e o o q

o i i o | i e | e a o o i i o e e o o i e e e o • e e | I

G o e o o u o e o I o o e i e I o o o e e e - - o ' 4 1 e o - - e - o

! _ ! _ ! _ ! _ ! _ ! _ ! . ! ! ! ! . i . ! ! ! ! | ! ! o a o , , , o , ,

o q e e e i a o ~ e ~ e e o - - i l - - I - - I - - I - - I - - e - - e - - | ' l - - l - - e - | - - i

o l ! e l | e e | o l e | i e o l l | e e a 4 I e l o l

I I I I I I I I I I I I I I I I I I I I I I I I I - - I ~ I - - ( ~ I

- _ o _ ° _ . _ ° _ ° _ _ o _ . _ o _ o . o . o _ o _ o _ o _ o _ o _ o _ o _ o _ ° _ ° ° . ° ° _ o _ ° ° i I e l i i l i i e l e e ! e e l e e e e I | l l o ¢ i

o ~ i s I e s i s s e s I l I s I e l e I e' s | ! I l e i!i i i?i:i i:i ilili ilili iii }iiiiiill m i l | i i o i o ! e 4 e I e e | e I l i e e i I e i i

o i e o i e ! i I | q I I | I e o l l I e i e e I D2 o ! . l . ! ! . ! _ , _ ! . ! ! ! ! ! ! ! ! ! ! ! ! ,-,-,-o-,',

- _ . . . . . - . - . . . - . . - o . , - . . ~ . - . ~ . . . ~ _ , _ . _ . - ~ , _ , - , - , - , - , - , - , - . . . . . . , . . . . .

; ! ! ! ! . a ! o , o a o ~ • o o ,~ o a o o o ~ o

' _ !_ !_ ! I . !_ !_ !_ !_o_ ! ! ! ! ! a o o , , , , ~ -o - , - ,

Fig. 7.

43

Volume 23, Number 1 I N F O R M A T I O N PROCESSING LETTERS 20 July 1986

, , n=21 E 3

l | | d | ! I - - | - - t - - 4 i a - - I I - - 4 - - | I - - I - - I - - i - - I - - i - - l - - i - - i ~ - - - _ _ . 4 - - 1 ~ 1 - - |

i I e - - I I I I ! I I I l I

-- --I--I--I I I--l--I--l--I--I I I--l--I I " - - - - - - - - - - - - - ~ _ .'_ :_ .'_ : _ . ' , . ~ _ ~_: i , , , , , , , , , , , - , - ,

! e ! . o o o o o o o J o o I o e o o I I - - l - - I ! -- -- I - - I - - I - - I - - I - - I - - I - - I - - I - - I = 1 - - I - - I

I I I I I I I I I I I I I I I I I I

I I I I I I I I I I I I ! I I I t I I I I I I I I I I ~ 1 I I ~ 1 ~ 1 - - 1 - - 1 ~ 1 - - 1

~ ! ! ! i i i ! ~ I -- I - - | - - l - - I - - I - - I - - I - - I - - I ' I - - I -- I - - I - - I I - - I I

E2 , , , i l l , , l i i l l - , - l - , - ,

l l , , , , l , , , , , l 1-1- l

• °~. . . o . o o o . E 4 '' ,,, ,, , , , , ,,. ,

° - - o - - o - - o _ o _ o _ ' ~ i . ~ i , , , , ~ ~ ° ° ° ° ° ° ° °

Fig. 8.

-E 5

- - E 1

(E) Solution for n ~ { 24 × k - 31 k ~ N }

Here, the location of the queens is described by the five sets

E 1 "= { (2 i+ 1, ] ( 3 n + 1) - i ) 1 0 ~ < i ~ ½ ( n - 1)},

E2:= ((4i, ¼(n + 3 ) - 1 - 2 ( i - 1))11 ~<i~< l ( n + 3)},

E3:= {(4i, n - 1 - 2 ( i - l ( n + 11)) ) I~(n + 11) < i ~ ¼ ( n - 1)},

E4 .'= { (4i + 2, ~(n - 5) - 2 i ) l0 ~< i ~< ~(n - 13) },

Es-'= ( ( 4 i + 2, n - 2 ( i - ~ ( n - 5 ) ) ) I ~ ( n - 5) ~<i~< ¼ ( n - 5)}

(see Fig. 8).

2. Verification of the consistency condition for case (E)

It is easily verified that the queens cannot attack each other horizontally or vertically and that queens within one of the sets E K (K = 1, 2 . . . . ,5) cannot attack each other along the diagonals. Hence, it remains to show that queens in set E K cannot attack queens in set E L (K =~ L) along a diagonal. To this end we give the sum and difference of the coordinates of an arbitrary queen in the following table:

Sum Difference

E] i + ~(3n + 5) 3 i - ~(3n - 3)

E 2 2i + l ( n + 7) 6 i - ~(n + 7)

E 3 2i + ¼(5n + 7) 6 i - ] (5n + 7)

E, 2i + ¼(n + 3) 6i - ¼(n - 13)

E 5 2i + -~(5n + 3) 6 i - ¼(5n - 13)

44

Volume 23, Number 1 INFORMATION PROCESSING LETTERS 20 July 1986

We p r o c e e d to c o m p a r e set E K wi th set EL, assuming tha t sums o r d i f fe rences are equa l an d der iv ing a c o n t r a d i c t i o n in e a c h case. N o t e tha t t he res t r ic t ions o n the p a r a m e t e r i a p p e a r i n g in the sets are crucial .

W e shall d e n o t e the p a r a m e t e r in the first n a m e d set b y i, a n d the o n e in the s econd n a m e d set by j.

2.1. Comparison of sums

E l, E2:

E l, E3: E l, E4: El , Es:

E 2, E3:

E 2, E4: E2, Es:

E 3, E4: E 3, E5:

E 4, Es:

i + ¼(3n + 5) = 2j + ¼(n + 7) =~ 2j - i = ½(n - 1). H o w e v e r , 2j - i ~< -~(n + 3) leads to a con t r ad ic - t ion s ince ½(n - 1) > ¼(n + 3) f o r n > 5.

i + ¼(3n + 5) = 2j + ¼(5n + 7) =~ i - 2j = ½(n + 1). i - 2j ~< ½(n - 1) =, con t r ad i c t i on .

i + ¼(3n + 5) = 2j + ¼(n + 3) ==, 2j - i = ½(n + 1). 2j - i ~< ¼(n - 13) =, con t r ad i c t i on .

i + ¼(3n + 5) = 2j + ¼(5n + 3) =, i - 2j = ½(n - 1). i - 2j < l ( n - 1) fo r n > 5 ~ con t r ad i c t i on . 2i + ¼(n + 7) = 2j + ¼(5n + 7) =~ 2(i - j ) = n =~ c o n t r a d i c t i o n .

2i + ¼(n + 7) = 2j + ¼(n + 3) ~ 2(i - j ) = - 1 ~ c o n t r a d i c t i o n .

2i + l ( n + 7) = 2j + ¼(5n + 3) =* i - j = l ( n - 1). i - j < ½(n - 1) for n > 5 ~ con t r ad i c t i on .

2i + ] ( 5 n + 7) = 2j + ¼(n + 3) ~ j - i = ½(n + 1). j - i < l ( n - 13) ==, con t r ad i c t i on . 2i + ¼(5n + 7) = 2j + ¼(5n + 3) =~ 2(i - j ) = - 1 ~ c o n t r a d i c t i o n .

2i + ] ( n + 3) = 2j + ¼(5n + 3) =, i - j = ½n =, c o n t r a d i c t i o n .

2.2. Comparison of differences

F o r b rev i ty we set n = 9 + 2k ' × 6 (k ' odd) .

E 1, E2: 3 i -

E 1, E3: 3 i -

E 1, E4: 3 i -

E l, Es: 3 i -

E2, E3: 6 i - E 2, E4: 6 i -

E 2, Es: 6 i -

E 3, E4: 6 i - E3, Es: 6 i -

E4, Es: 6 i -

¼(3n - 3) = 6j - l ( n + 7) =, i - 2j = 4 + 2k ' ~ c o n t r a d i c t i o n .

¼(3n - 3) = 6j - ¼(5n + 7) ==* 2j - i = ~ + 2k ' =~ co n t r ad i c t i o n .

¼(3n - 3) = 6j - ¼(n - 13) =~ i - 2j = ~ + 2k ' ~ c o n t r a d i c t i o n .

¼(3n - 3) = 6j - ¼(5n - 13) =~ 2j - i = ~ + 2k ' = c o n t r a d i c t i o n .

¼(n + 7) = 6j - 1 (5n + 7) =* 6(j - i) = n =, c o n t r a d i c t i o n .

¼(n + 7) = 6j - ¼(n - 13) ==0 6(i - j ) = 5 =* c o n t r a d i c t i o n .

¼(n + 7) = 6j - 1 (5n - 13) =~j - i = 4 + 2k ' =, co n t r ad i c t i o n l

¼(5n + 7) = 6j - ¼(n - 13) ~ i - j = ~ + 2k ' =~ c o n t r a d i c t i o n .

¼(5n + 7) = 6j - ¼(5n - 13) =~ 6(j - i) = - 5 =, c o n t r a d i c t i o n .

¼(n - 13) = 6j - ¼(5n - 13) = 60 - i) = n ==* c o n t r a d i c t i o n .

F r o m the c o m p a r i s o n s above it is n o w c lear tha t we d o i n d eed o b t a i n a solut ion. T h e o the r cases m a y be

t r ea ted in a s imi lar fashion. ( I t s hou ld b e c lear to the r eade r w h y we have no t given an expl ic i t p r o o f in each case!)

3. Concluding remarks

(1) A l t h o u g h we h a v e o b t a i n e d a so lu t i on fo r eve ry n > 3, we are f a r f r o m ob ta in ing all so lu t ions in each

case. H o w e v e r , it is easi ly seen tha t fo r n ~ {12 × k - 3 [k ~ N} (i.e., fo r cases (D) and (E)) the n u m b e r of

so lu t ions is at least k: R e m o v i n g the t op r o w a n d 'g lue ing ' it to the b o t t o m of the b o a r d k - 1 t imes gives

k - 1 new so lu t ions in this case. A s imi la r o b s e r v a t i o n seems to a p p l y to so lu t ion p a t t e rn (B) b u t no t to any o the r o f the g iven solut ions.

(2) I t is a s ton i sh ing tha t fo r n = 0, 1, 4, 5 m o d 6 a so lu t ion m a y b e c o n s t r u c t e d qui te easily, whils t fo r the r em a in ing res idue classes m o d u l o 6 the c o n s t r u c t i o n o f a so lu t ion is co n s id e r ab ly m o r e compl i ca ted . T h e pre t t iness o f the l a t t e r so lut ions a p p e a r s as a r e d e e m i n g f ea tu re t hough .

45

Volume 23, Number 1 INFORMATION PROCESSING LET/~ERS 20 July 1986

(3) It is clear that if we consider a solution as a permutation, then once one solution has been obtained for a fixed n, all others may be constructed by applying a 'certain' subset of the symmetric group S n. Knowledge of the structure of this subset would be, in a sense, equivalent to the complete solution of the problem.

(4) The role of the residue classes is not clear: One might well ask whether the classes modulo 6 carry any structural significance.

(5) The well-known backtrack algorithm enumerates both rows and columns in their natural order 1, 2 , . . . ,n. By varying this order (e.g., using for even n: in , ½n + 1, an - 1, ½n + 2, ½n - 2, . . . ) we found that it significantly influences the time behaviour of the algorithm. Surprisingly enough, among all the different orders tried, the natural one gave the best performance.

(6) It should be obvious from the remarks above that obtaining all solutions for arbitrary n remains a fascinating problem.

Acknowledgment

We would like to thank the anonymous referee for suggesting several corrections and improvemen

References

[1] J. Ginsburg, Gauss's arithrnetization of the problem of 8 queens, Scripta Math. 5 (1939) 63-66.

[2] S.W. Golomb and L.D. Baumert, Backtrack programming, J. ACM 12 (4) (1965) 516-524.

[3] R.W. Irving, Permutation backtracking in lexicographic order, Comput. J. 27 (4) (1984) 373-375.

[41 E. Netto, Lehrbuch der Combinatorik (Teubner, Stuttgart, 1901).

[5] E.M. Reingold, J. Nievergelt and N. Deo, Combinatorial Algorithms: Theory and Practice (Prentice-Hall, En- glewood Cliffs, NJ, 1977).

46