Post Reply 
N-queens for Casio fx-3650P, fx-3650PII, fx-50FH
05-10-2023, 02:38 PM
Post: #1
N-queens for Casio fx-3650P, fx-3650PII, fx-50FH
The "chopping block" n-queens algorithm from "Mathematical Recreations for the Programmable Calculator" has been used to good effect on other calculators that lack indirect addressing (see here, here, and here), so here's a few more for the pile.

This is a quick conversion of the Sharp EL-5120 version I wrote. Not only do these solar-powered programmable Casios lack any sort of indirect addressing or subroutines, they also lack int/frac functions! Fortunately they do have a rounding function that can be substituted here without much hassle.

The fx-3650PII and fx-50FH are nearly identical in terms of programming functionality, and share the exact same program, but the fx-3650 has some substantial differences (or more accurately, omissions). It is lacking an absolute value function, but this is easily worked around in this program as it is used in only one place. Curiously, it's also lacking < and <=, but a simple rearrangement allows for using > instead. The biggest difference for this program is that the rounding function is used differently on this model. Thus there are two separate programs here: one for the fx-50FH and fx-3650PII, and one for the fx-3650P.

Note that I've used line breaks to separate the program statements for better readability, but you will of course use colons to separate the statements when entering them into the calculator. Functionally, it makes no difference which of the four program areas you use, but for the purposes of timing, I entered them into P1, in case that somehow affects speed.

When running the program, you will be prompted to enter the board size. Enter a value between 4 and 9 and press EXE to start (e.g. enter 8 for an 8x8 board). The program will stop and display the first solution found. Press EXE to continue finding additional solutions.

fx-50FH, fx-3650P II:

Code:
?→M
Fix 0
0→A
0→C
Lbl 1
A=M⇒Goto 6
1→B
Lbl 3
C→D
0→Y
Lbl 7
Y+1→Y
D=0⇒Goto 8
.1D→D
10(D-Rnd(D-.5))→X
Rnd(D-.5)→D
X=B⇒Goto 4
Abs(X-B)=Y⇒Goto 4
Goto 7
Lbl 8
10C+B→C
A+1→A
Goto 1
Lbl 6
C◢
Lbl 4
B=M⇒Goto 5
B+1→B
Goto 3
Lbl 5
A-1→A
A<0⇒Goto 9
.1C→C
10(C-Rnd(C-.5))→B
Rnd(C-.5)→C
Goto 4
Lbl 9
Norm 1

fx-3650P:

Code:
?→M
Fix 0
0→A
0→C
Lbl 1
A=M⇒Goto 6
1→B
Lbl 3
C→D
0→Y
Lbl 7
Y+1→Y
D=0⇒Goto 8
.1D→D
D-.5
Rnd
10(D-Ans)→X
D-.5
Rnd
Ans→D
X=B⇒Goto 4
X-B=Y⇒Goto 4
B-X=Y⇒Goto 4
Goto 7
Lbl 8
10C+B→C
A+1→A
Goto 1
Lbl 6
C◢
Lbl 4
B=M⇒Goto 5
B+1→B
Goto 3
Lbl 5
A-1→A
0>A⇒Goto 9
.1C→C
C-.5
Rnd
10(C-Ans)→B
C-.5
Rnd
Ans→C
Goto 4
Lbl 9
Norm 1

Timings for an 8x8 board:

fx-3650P - 0:24:49
fx-3650PII - 0:05:49
fx-50FH - 0:06:42

I don't have an fx-50FHII (yet), so if anybody would like to do the honors, be my guest!
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
N-queens for Casio fx-3650P, fx-3650PII, fx-50FH - Dave Britten - 05-10-2023 02:38 PM



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