What does your phone number spell out if changed to letters? A friend’s phone number, 438-5678, spells GET LOST. A bank’s auto loan department answers NEXT CAR.
To encode your number into a readable word, you could just gaze at your telephone dial. But every digit has three letters. A seven digit phone number has 2,187 different possibilities! Now a ZX80/1 (4K/1K, 8K/2K) can do it for you.
The program initializes two counters, P and Q (lines 5&7). P counts combinations printed 40 at a time. Q keeps a running total till the ZX80 prints 2187 combinations. You enter the digits via lines 10-22. The 2187 words are produced by 2187 iterations through the seven nested FOR loops (lines 24-110). The subroutine at 500-506 prints each letter by converting the digit into a printable ASCII value. It converts 2, for example, into ASCII values 38, 39, and 40, which print A, B, and C. The subroutine at 300-306 signals the ZX80 to print the next 40 combinations. Lines 200-202 end the program.
RUN, then enter your phone number (hit NL after each digit). About 15 seconds later the first 40 combinations appear. Press NL to see successive groups. The last one ends with “FINE.” Don’t input the digits 1 and 0–they have no letters on the phone dial. The program suppresses Q and Z since they do not appear on the dial.
This program was inspired by Harvey M. Deitel’s Introduction to Computer Programming (Prentice-Hall), a fine book for learning BASIC.
5 LET P=0
7 LET Q=0
10 INPUT A
12 INPUT B
14 INPUT C
16 INPUT D
18 INPUT E
20 INPUT F
22 INPUT G
24 FOR Z=0 TO 2
26 FOR Y=0 TO 2
28 FOR X=0 TO 2
30 FOR W=0 TO 2
32 FOR V=0 TO 2
34 FOR U=0 TO 2
36 FOR T=0 TO 2
38 LET M=A
40 LET N=T
42 GO SUB 500
44 LET M=B
46 LET N=U
48 GO SUB 500
50 LET M=C
54 LET N=V
56 GO SUB 500
58 LET M=D
60 LET N=W
62 GO SUB 500
64 LET M=E
66 LET N=X
68 GO SUB 500
70 LET M=F
72 LET N=Y
74 GO SUB 500
76 LET M=G
78 LET N=Z
80 GO SUB 500
82 PRINT " ";
84 LET P=P+1
85 LET Q=Q+1
86 IF P>39 THEN GO SUB 300
88 IF Q=2187 THEN GO TO 200
90 NEXT T
92 NEXT U
94 NEXT V
96 NEXT W
98 NEXT X
100 NEXT Y
110 NEXT X
200 PRINT "FINE"
202 STOP
300 INPUT R$
302 LET P=0
304 CLS
306 RETURN
500 LET J=2*M+32+M+N
502 IF J>53 THEN LET J=J+1
504 PRINT CHR$(J);
506 RETURN
Syntactic Sum:-29058, 4K; 44104, 8K
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.