(20S, 21S) N-Queens Benchmark
02-22-2022, 09:05 PM
Post: #1
 Dave Britten Senior Member Posts: 2,140 Joined: Dec 2013
(20S, 21S) N-Queens Benchmark
Another pair of calculators with no indirect addressing that you would think can't handle the N-Queens solver. The "chopping block" algorithm featured in "Mathematical Recreations for the Programmable Calculator" is suitable for both of these models, although it does require some finesse to fit the program into the 99 available steps of memory while also coping with the algebraic input and two available comparison tests (x=0, x<=y).

To run this program, enter the board size (e.g. 8 for 8x8), and press XEQ A. For an 8x8 board, the program will stop with the first solution in approximately 5m12s on a 20S (the 21S is probably the same speed, but I haven't tested it). You can press R/S to continue finding more solutions, and the program will stop with -1 in the display when no more solutions can be found. The program can handle board sizes up to 9x9.

Code:
LBL 0
*
1
0
=
RTN
LBL A
CLRG
STO 9
LBL 1
RCL 0
-
RCL 9
=
x=0?
GTO 6
1
STO 1
LBL 3
RCL 2
STO 3
C
STO 4
LBL 9
1
STO+ 4
RCL 3
*
.
1
=
x=0?
GTO 7
-
IP
STO 3
=
XEQ 0
-
RCL 1
=
x=0?
GTO 4
ABS
-
RCL 4
=
x=0?
GTO 4
GTO 9
LBL 7
RCL 2
XEQ 0
+
RCL 1
=
STO 2
1
STO+ 0
GTO 1
LBL 4
RCL 1
-
RCL 9
=
x=0?
GTO 5
1
STO+ 1
GTO 3
LBL 5
1
STO- 0
0
INPUT
RCL 0
x<=y?
GTO 8
RTN
LBL 8
C
RCL 2
*
.
1
=
-
IP
STO 2
=
XEQ 0
STO 1
GTO 4
LBL 6
RCL 2
R/S
GTO 4

Checksum=DD03
 « Next Oldest | Next Newest »

User(s) browsing this thread: 1 Guest(s)