*The Museum of HP Calculators*

**HP Articles Forum**

[Return to the Index ]

[ Previous | Next ]

**N-queens benchmark and the HP-17BII**

*Posted by ***Thomas Klemm** on **7 Feb 2011, 5:48 a.m.**

## Equation for the 8-queens problem

QUEENS:
Q=A+B+C+D+E+F+G+H+
(I:1:8:1:
(J:1:8:1:
IF(I<>J AND SQ(I-J)<>1:
(K:1:8:1:
IF(I<>K AND SQ(I-K)<>4
AND J<>K AND SQ(J-K)<>1:
(L:1:8:1:
IF(I<>L AND SQ(I-L)<>9
AND J<>L AND SQ(J-L)<>4
AND K<>L AND SQ(K-L)<>1:
(M:1:8:1:
IF(I<>M AND SQ(I-M)<>16
AND J<>M AND SQ(J-M)<>9
AND K<>M AND SQ(K-M)<>4
AND L<>M AND SQ(L-M)<>1:
(N:1:8:1:
IF(I<>N AND SQ(I-N)<>25
AND J<>N AND SQ(J-N)<>16
AND K<>N AND SQ(K-N)<>9
AND L<>N AND SQ(L-N)<>4
AND M<>N AND SQ(M-N)<>1:
(O:1:8:1:
IF(I<>O AND SQ(I-O)<>36
AND J<>O AND SQ(J-O)<>25
AND K<>O AND SQ(K-O)<>16
AND L<>O AND SQ(L-O)<>9
AND M<>O AND SQ(M-O)<>4
AND N<>O AND SQ(N-O)<>1:
(P:1:8:1:
IF(I<>P AND SQ(I-P)<>49
AND J<>P AND SQ(J-P)<>36
AND K<>P AND SQ(K-P)<>25
AND L<>P AND SQ(L-P)<>16
AND M<>P AND SQ(M-P)<>9
AND N<>P AND SQ(N-P)<>4
AND O<>P AND SQ(O-P)<>1:
L(A:I)xL(B:J)xL(C:K)xL(D:L)xL(E:M)xL(F:N)xL(G:O)xL(H:P)/0
:0)):0)):0)):0)):0)):0)):0)))

## Solution

Solve the equation for *Q*. After a while (3:29) you get an error message:

SOLUTION NOT FOUND

Now you can recall the solution in the variables *A-H*.
The result *{ 1, 5, 8, 6, 3, 7, 2, 4 }* corresponds to the following configuration:

A B C D E F G H
+---+---+---+---+---+---+---+---+
8 | | | # | | | | | |
+---+---+---+---+---+---+---+---+
7 | | | | | | # | | |
+---+---+---+---+---+---+---+---+
6 | | | | # | | | | |
+---+---+---+---+---+---+---+---+
5 | | # | | | | | | |
+---+---+---+---+---+---+---+---+
4 | | | | | | | | # |
+---+---+---+---+---+---+---+---+
3 | | | | | # | | | |
+---+---+---+---+---+---+---+---+
2 | | | | | | | # | |
+---+---+---+---+---+---+---+---+
1 | # | | | | | | | |
+---+---+---+---+---+---+---+---+

## References

Eight queens puzzle

Calculator Speed Benchmark using the N-Queens Problem

*Edited: 7 Feb 2011, 6:27 a.m. *

[ **Return to the Message Index** ]

Go back to the main exhibit hall