Sharp MZ80K

My Solution sent to C&VG Magazine in Sharp MZ80K Basic

Below is a listing of my submission to C&VG magazine solving the Beermat puzzle the code is annotated and a description of the variables used given in the second listing below the main code.

Links to two further pages Codea Solver Bri_G on my iPad using Codea and C&VG Solution Commodore PET which is the puzzle creators program solution also in old Basic language dialects from almost 40 years ago.

In a similar manner to the Commodore PET, data was loaded and saved on casette tape - bit with the Sharp MZ80K you also had to load the Basic language first on cassette tape. The listing is again littered with control characters used to control printing positions and characters on the screen.

My Own Sharp MZ80K (Basic) Listing

Sharp MZ80K Basic
                            
10 REM Disc Matching Problem Solver
15 REM by BD Gott
16 TI$ = "000000"
20 REM Disc String Definition
25 AA$ = "!!R2W1W1W5W5R2R4R7R7R2W3R7W3R4R4R7R2W1W1W5W5R2R4R7R7R2W3R7W3R4R4R7"
30 AB$ = "!!R4R2R7W3R2W6W5R2WIW3W6R2W1R4W3R4R4R2R7W3R2W6W5R2WIW3W6R2W1R4W3R4"
35 BAS = "!!R7R4W5R7R4W5R4R2R7W1R4W1W3W1R2W5R7R4W5R7R4W5R4R2R7W1R4W1W3W1R2W5"
40 BB$ = "!!W1W5W1R2R2R7R2W5W5W3R4W5W3R7R2R4W1W5W1R2R2R7R2W5W5W3R4W5W3R7R2R4"
45 CAS = "!!R4W3W5R7W6R4R2R7W5R4W1R4R2W1R7W1R4W3W5R7W6R4R2R7W5R4W1R4R2W1R7W1"
50 CB$ = "!!W1W3W1R7W5W3R7R2R7W3W6R4R7W5W6R2W1W3W1R7W5W3R7R2R7W3W6R4R7W5W6R2"
55 DA$ = "!!R2R4R2W6W1R7W1R2R7R4R4W6W3W5W5W1R2R4R2W6W1R7W1R2R7R4R4W6W3W5W5W1"
60 DBS = "!!W3W1W5R4R4W1W5W1R4W3R7W5R4W6W3W5W3W1W5R4R4W1W5W1R4W3R7W5R4W6W3W5"
65 REM select Characters for first Disc
66 REM First side
70 FOR P = 1 to 8 |
75 A1$ = MID$(AA$,4*P-1,2)
80 A2$ = MID$(AA$,4*P+1,2)
85 H1$ = MID$(AA$,4*P+7,2)
90 H2$ = MID$(AA$,4*P+9,2)
91 PRINT "[H]"; TAB(33); "P = ";P
95 GOSUB 155
96 VA = VA + 1: PRINT "[H]↓↓"; TAB(32); "VA = "; VA
100 NEXT P
105 REM select Characters for first Disc
110 REM Second side
70 FOR P = 9 to 16
115 A1$ = MID$(AB$,4*P-33,2)
120 A2$ = MID$(AB$,4*P-31,2)
125 H1$ = MID$(AB$,4*P-25,2)
130 H2$ = MID$(AB$,4*P-23,2)
131 PRINT "[H]"; TAB(32); "P = ";P
135 GOSUB 155
136 VB = VB + 1: PRINT "[H]↓↓"; TAB(32); " VB= "; VB
140 NEXT P
145 GOTO 725
150 REM Definition of String Variables
151 REM For each Orientation
155 FOR Q = 1 TO 6
160 ON Q GOTO 165, 175, 185, 195, 205, 215
165 JS = "1,2,3,4":X1$ = BA$: X2$ = BB$: X3$ = CA$: X4$ = CB$: X5$ = DA$: X6$ = DB$
170 GOSUB 240
171 NEXT OQ
175 JS = "1,2,4,3":X1$ = BA$: X2$ = BB$: X3$ = DA$: X4$ = DB$: X5$ = CA$: X6$ = CB$
180 GOSUB 240
181 NEXT OQ
185 JS = "1,2,3,4":X1$ = CA$: X2$ = CB$: X3$ = BA$: X4$ = BB$: X5$ = DA$: X6$ = DB$
190 GOSUB 240
191 NEXT Q
195 JS = "1,2,3,4":X1$ = CA$: X2$ = CB$: X3$ = DA$: X4$ = DB$: X5$ = BA$: X6$ = BB$
200 GOSUB 240
201 NEXT Q
205 JS = "1,2,3,4":X1$ = DA$: X2$ = DB$: X3$ = BA$: X4$ = BB$: X5$ = CA$: X6$ = CB$
210 GOSUB 240
211 NEXT Q
215 J$ = "1,2,3,4":X1$ = DA$: X2$ = DB$: X3$ = CA$: X4$ = CB$: X5$ = BA$: X6$ = BB$
220 GOSUB 240
221 NEXT Q
225 RETURN
230 REM Examining both sides of the second Disc
231 REM for character matches 
235 REM Second Disc First Side 
240 FOR X = 1 TO 8
245 B1$ = MID$(X1$,4*X-1,2) 
250 B2$ = MID$(X1$,4*X+1,2) 
250 IF A1$ = B2$ GOTO 265 
260 GOTO 266
265 IF A2$ = B1$ GOSUB 330
266 VC= VC + 1: PRINT "[H]↓↓↓↓"; "VC = "; VC
270 NEXT X
275 REM Second Disc Second Side 
285 FOR X = 9 TO 16
290 B1$ = MID$(X2$,4*X-33,2) 
295 B2$ = MID$(X2$,4*X-31,2) 
300 IF A1$ = B2$ GOTO 310 
305 GOTO 311
310 IF A2$ = B1$ GOSUB 345
311 VD= VD + 1: PRINT "[H]↓↓↓↓↓"; "VD = "; VD
315 NEXT X
320 RETURN
325 REM Identify Characters AT C
326 REM For Matches
330 C1$ = MID$(X1$,4*X+23,2) 
335 C2$ = MID$(X1$,4*X+25,2) 
340 GOTO 365
345 C1$ = MID$(X2$,4*X-9,2) 
350 C2$ = MID$(X2$,4*X-7,2)
355 REM Examine Both Sides Of The Third Disc
356 REM For Character Matches 
360 REM Third Disc First Side 
365 FOR Y = 1 TO 8
370 D1$ = MID$(X3$,4*Y-1,2) 
375 D2$ = MID$(X3$,4*Y+1,2) 
380 IF D1$ = C2$ GOTO 390 
385 GOTO 391
390 IF D2$ = C1$ GOSUB 445
391 VE = VE + 1: PRINT "[H]↓↓↓↓↓↓"; "VE = "; VE
395 NEXT Y
396 REM Third Disc Second Side 
365 FOR Y = 9 TO 16
370 D1$ = MID$(X3$,4*Y-33,2) 
375 D2$ = MID$(X3$,4*Y-31,2) 
380 IF D1$ = C2$ GOTO 425 
385 GOTO 426
390 IF D2$ = C1$ GOSUB 460
391 VF = VF + 1: PRINT "[H]↓↓↓↓↓↓↓"; "VF = "; VF
395 NEXT Y
435 RETURN
440 REM Identify Characters AT E
441 REM For Matches
445 E1$ = M1D$(X3$,4*X+23,2) 
450 E2$ = M1D$(X3$,4*X+25,2) 
455 GOTO 475
460 C1$ = M1D$(X4$,4*X-9,2) 
465 C2$ = MID$(X4$,4*X-7,2)
470 REM Examine Both Sides Of The Fourth Disc
471 REM For Character Matches
472 REM Fourth Disc First Side 
475 FOR Z = 1 TO 8
480 F1$ = M1D$(X5$,4*Z-1,2) 
485 F2$ = M1D$(X5$,4*Z+1,2) 
490 IF DF1$ = E2$ GOTO 500 
495 GOTO 501
500 IF F2$ = E1$ GOSUB 560
501 VG = VG + 1: PRINT "[H]↓↓↓↓↓↓↓"; "VG = "; VG
505 NEXT Z
510 REM Fourth Disc Second Side 
515 FOR Z = 9 TO 16
520 F1$ = M1D$(X6$,4*Z-33,2) 
525 F2$ = M1D$(X6$,4*Z-31,2) 
530 IF F1$ = E2$ GOTO 540 
535 GOTO 541
540 IF D2$ = C1$ GOSUB 575
541 VH = VH + 1: PRINT "[H]↓↓↓↓↓↓↓"; "VH = "; VH
545 NEXT Z
550 RETURN
550 REM Identify Characters AT G 
556 REM For Matches
560 Gl$ = M1D$(X5$,4*Z+23,2) 
565 G2$ = M1D$(X5$,4*Z+25,2) 
570 GOTO 475
575 G1$ = M1D$(X6$,4*Z-9,2) 
580 G2$ = M1D$(X6$,4*Z-7,2)
585 REM Examine Both Sides Of The Fourth Disc
586 REM For Character Matches
590 IF G1$ = H2$ GOTO 600
591 VM = VM + 1: PRINT "[H]↓↓↓↓↓↓↓↓↓↓"; TAB(32);"VM = "; VM
595 RETURN
600 IF G2$ = H1$ GOTO 609
601 VN = VN + 1: PRINT "[H]↓↓↓↓↓↓↓↓↓↓↓"; TAB(32);"VN = "; VN
605 RETURN
609 ST$ = T1$: PRINT "[H]↓↓↓↓↓↓↓↓↓↓↓"; TAB(30);"ST$ "; ST$
610 FS = FS + 1
611 PRINT "[H]↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓"; TAB(32);"SFS = "; FS
615 IF P <= 8 THEN K$ = "A" 
620 IF P> 8 THEN K$ = "B" 
625 IF X <= 8 THEN L$ = "A" 
630 IF X > 8 THEN L$ = "B" 
635 IF Y <= 8 THEN M$ - "A" 
640 IF Y > 8 THEN M$ = "B" 
645 IF Z <= 8 THEN N$ = "A" 
650 IF Z > 8 THEN N$ = "B"

655 PRINT "[H] SOLUTION No. : ";first
660 PRINT " ORIENTATION, CLOCKWISE IS  ";J$

665 PRINT "IN CLOCKWISE ROTATION"
666 PRINT 
670 PRINT "DISC 1, SIDE ";K$;" CHARACTERS"
671 PRINT A1$;" AND "; A2$;" AT THE RHS."
675 PRINT "ALSO ";H1$;" AND ";H2$;" AT THE"
676 PRINT "BOTTOM."
677 PRINT 
680 PRINT " DISC ";MID$(J$,3,1);", SIDE ";L$;" CHARACTERS"
681 PRINT B1$;" AND ";B2$;" AT THE LHS."
685 PRINT "ALSO ";C1$;" AND ";C2$;" AT THE ↓←←←←←←←←←←←←←←←←←←←←←BOTTOM."
686 PRINT 
690 PRINT "DISC ";MID$(J$,5,1);", SIDE ";M$;" CHARACTERS"
691 PRINT D1$;" AND ";D2$;" AT THE TOP."
695 PRINT "ALSO ";E1$;" AND ";E2$;" AT THE LHS."
700 PRINT "↓DISC ";MID$(J$,7,1);", SIDE ";N$;" CHARACTERS"
701 PRINT F1$;" AND ";F2$;" AT THE RHS."
705 PRINT "ALSO ";G1$;" AND ";G2$;" AT THE TOP."
715 PRINT
720 RETURN

725 PRINT "[H]↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ FINAL TOTAL OF : ";FS;
726 PRINT "  IS POSSIBLE."
749 FT$ = TI$: PRINT "[H]↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓";TAB(30);"FT$ = ";FT$
750 End
							
                          
Programs Basic Definitions
                            
"VA to VH - number of first/second face combinations at Disc interfaces
VM number of combinations (fail or pass) on 1 character match between fourth & third Discs
VH number of combinations (fail or pass) on both character matches between fourth & third Discs
P number of faces on disc 1 (first Disc)
Q number of orientations adopted by other three discs
X number of faces checked on the second disc 2/3 or 4
Y number of faces checked on the third disc 2/3 or 4
Z number of faces checked on the fourth disc 2/3 or 4
AA$ TO DB$ - definition of Disc/Face as XA and XB strings respectively
B1$ and B2$ - Characters used for comparisonsecond disc LHS 
Cl$ and C2$ - Characterised for comparison second disc Bottom 
D1$ and D2$ - Characterised for comparison third disc Top 
E1$ and E2$ - Characterised for comparison third disc LHS 
F1$ and F2$ - Characterised for comparison fourth disc RHS 
Gl$ and G2$ - Characterised for comparison fourth disc Top 
Hl$ and H2$ - Characterised for comparison first disc Bottom
J$ - string used for definition of orientations
X1$, X2$, X3$, X4$ - strings used to define the different orientations from AA$ to DB$ 
K$, L$, M$, N$ - strings used to define which disc face is visible on each disc for the 
final Solution
ST$ - string variable which holds the time to achieve solution
FT$ - string variable used to hold the time to complete the whole program 
FS - Variable which holds the total number of complete solutions"