Post Reply 
(EL-5120) N-Queens Benchmark
02-22-2022, 08:11 PM (This post was last modified: 02-22-2022 08:23 PM by Dave Britten.)
Post: #1
(EL-5120) N-Queens Benchmark
The Sharp EL-5120 is a pleasant, though in some ways underwhelming calculator. About the size of an HP Pioneer, and similar in functions to a 32S/32SII, it's equipped with a three-line display of dot-matrix characters, and roughly 1 KB of RAM. It has solve and integrate functions, and can store a list of equations for later use. Interestingly, it allows for two-character letter+number local variables in equations and programs. However, this machine is quite wasteful with its memory, so that 1 KB doesn't get you too much further than the 384 bytes of a 32SII (which was already pretty wasteful with its 1.5-byte program steps). At least you get a lot more labels to use, and you can GOTO or GOSUB to local labels within a program, but you can't have one program call another.

The EL-5120 is programmable in a simple BASIC-like language that's very similar to that of Sharp's graphing calculators, but entirely lacking in any sort of indirect addressing capability. This rules out the possibility of running the N-Queens solver algorithm, right? Wrong! The "chopping block" algorithm from "Mathematical Recreations for the Programmable Calculator" (which I previously crammed into the HP 65) requires no indirect addressing, and needs only 5 or 6 memories to find solutions on a board up to 9x9.

Below is the listing for NQUEENS, which probably doesn't need too much explanation. Functions like IPART, FPART, ABS, IF, GOTO, and PRINT all function exactly like you would expect them to, and variable assignments take the form A=0, E=E+1, etc. Run the program, type in the board size (e.g. 8 for 8x8), and press ENTER to start solving. The program produces a solution for an 8x8 board in about 4m27s. You can press ENTER to start looking for another solution, or press QUIT or ON to stop the program.

Code:
INPUT N
A=0
C=0
LABEL 1
IF A=NGOTO 6
B=1
LABEL 3
D=C
E=0
LABEL 7
E=E+1
IF D=0GOTO 8
D=.1D
X=10FPART D
D=IPART D
IF X=BGOTO 4
IF ABS (X-B)=EGOTO 4
GOTO 7
LABEL 8
C=10C+B
A=A+1
GOTO 1
LABEL 6
PRINT C
WAIT
LABEL 4
IF B=NGOTO 5
B=B+1
GOTO 3
LABEL 5
A=A-1
IF A<0GOTO 9
C=.1C
B=10FPART C
C=IPART C
GOTO 4
LABEL 9
PRINT"DONE
END
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(EL-5120) N-Queens Benchmark - Dave Britten - 02-22-2022 08:11 PM
RE: (EL-5120) N-Queens Benchmark - xerxes - 02-24-2022, 10:05 PM
RE: (EL-5120) N-Queens Benchmark - xerxes - 02-26-2022, 03:22 PM



User(s) browsing this thread: