Fifteen Puzzle

Author(s): Jon Passler
Publication: Syntax
Pub Details: Syntax/Syntax ZX80 v3 n10 (Volume 3, Issue 10)
Date: October 1982
Pages: 17

This 8K/1K version of Fifteen Puzzle retains most features of the 4K version (Apr.82).

Invented by Sam Loyd in 1878, it consists of 15 numbered blocks and 1 space in a 4×4 matrix.

The objective is to order the matrix by moving the twin dashes horizontally or vertically with the the fewest moves.

 1  2  3  4
 5  6  7  8
 9 10 11 12
13 14 15 --

In line 4, B$ first five characters are shift graphics 2, 4, 5, E, and S.

When you want to terminate the program, Enter STOP (shift A) and the screen will blank. To play Fifteen Puzzle again, just hit RUN, and ENTER.

   2 RAND
4 LET B$="▝▖▌▛▓£$?"
6 LET S=0
8 DIM A$(16)
10 FOR I=1 TO 16
12 LET R=RND*16+.5
14 IF A$(R)<>" " THEN GOTO 12
16 LET A$(R)=CHR$ I
18 NEXT I
20 FOR I=1 TO 15
22 IF I<9 THEN IF A$(CODE B$(I))="(" THEN LET S=S+1
24 FOR J=I+1 TO 16
26 IF A$(I)>A$(J) THEN LET S=S+1
28 NEXT J
30 NEXT I
32 IF INT (S/2)*2<>S THEN GOTO 6
34 CLS
36 FOR I=1 TO 16
38 LET S=CODE A$(I)
40 IF S<10 THEN PRINT " ";
42 IF S<16 THEN PRINT S;" ";
44 IF S=16 THEN PRINT "-- ";
46 IF INT (I/4)*4=I THEN PRINT
48 NEXT I
50 INPUT S
52 FOR I=1 TO 16
54 IF A$(I)=CHR$ S THEN LET J=I
56 IF A$(I)="(" THEN LET R=I
58 NEXT I
60 IF ABS (J-R)<>1 AND ABS (J-R)<>4 THEN GOTO 50
62 LET A$(R)=A$(J)
64 LET A$(J)="("
66 GOTO 34
SYNTACTIC SUM: 38182, 8K

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.