Mouthful
Dear Editor:
Don Day’s “A Mouthful for Every Occasion” (SYNC 2:5) can be made to run in 8K ROM/1K RAM without decreasing the size or number of words.
The program below uses a three-dimensional string array at line 30 as the method. This is not mentioned in the manual (at least the first US edition).
To use the program, type in the lines. Then use GOTO 20 and ENTER. Next input one of Don’s tables. Press ENTER after each word. Each entry may be up to 10 characters long. You do not have to add spaces to fill out the array; the ZX81 does it for you.
10 GOTO 100
20 FAST
30 DIM A$(5,3,10)
40 FOR Y=1 TO 3
50 FOR X=1 TO 5
60 INPUT P$
70 LET A$(X,Y)=P$
80 NEXT X
90 NEXT Y
100 SLOW
110 PRINT "PRESS ENTER TO GENERATE PHRASE"
120 INPUT B$
130 CLS
140 PRINT AT 10,0;""
150 FOR X=1 TO 3
160 PRINT A$(INT (RND*5)+1,X);" ";
170 NEXT X
180 PRINT AT 15,0;"AGAIN? (Y/N)"
190 PAUSE 10000
200 IF INKEY$="Y" THEN GOTO 130
210 STOP
After entering your list, SAVE the program. Then use GOTO 10 and ENTER to begin or you will lose your list.
Charles Godwin
[address omitted]
Oxnard, CA
Draw and Store
Dear Editor:
The following changes in J. J. Hollandsworth’s excellent “Draw and Store” routine (SYNC 2:6) permit SAVEing the display on tape in 1K RAM. The stored picture is displayed almost instantly upon reLOADing from tape. Note that all underlined words in the PRINT statements are token words to conserve RAM.
1 REM HARTUNG
5 CLS
500 PRINT AT 21,0;"KEY ENTER TO SAVE "
510 PAUSE 40000
520 IF CODE INKEY$=118 THEN SAVE "DRAW"
530 PRINT AT 21,0;" INPUT NEW PLOT ? Y OR N"
540 PAUSE 40000
550 IF INKEY$="Y" THEN RUN
560 GOTO 540
Enter lines 10 through 80 of the original listing, then enter the lines below.
Notes:
510: POKE 16437,255 is not required here or at line 30 with the improved 8K ROM.
550: Start the recorder, then key ENTER twice to SAVE to tape.
Robert Hartung
[address omitted]
Palmyra, NY
Rounding Off
Dear Editor:
James E. Stauffer’s article “Rounding off with Conditional Tests” in SYNC 2:4 could be expanded to show how problems could be reduced and performance improved by a change in the methods used. The program below suggests some possibilities in this direction.
I used a table of squares to save multiplication, set the loop limits to remove unworkable cases, and substituted additional for multiplication. Then I developed algebraically a method that directly generates only the “Pythagorean Triples.” An efficient method from Euclid computes the greatest common divisor to eliminate triples that are multiples of smaller triples. Since I prefer right-justified numbers, I used a different method of tabulating the answers. Lastly, I deferred computing the third component of each triple until I had decided to format and print the triple.
10 DIM S(20)
20 FOR N=1 TO 20
30 LET S(N)=N*N
40 NEXT N
50 FOR N=1 TO 19
60 LET N2=S(N)
70 FOR M=N+1 TO 20
80 LET M2=S(M)
90 LET A=M2-N2
100 LET B=M*N
110 LET B=B+B
120 IF A<=B THEN GOTO 160
130 LET X=A
140 LET A=B
150 LET B=X
160 LET DN=B
170 LET DR=A
180 LET R=DN-INT (DN/DR)*DR
190 IF NOT R THEN GOTO 230
200 LET DN=DR
210 LET DR=R
220 GOTO 180
230 IF DR<>1 THEN GOTO 280
240 LET A$=STR$ A
250 LET B$=STR$ B
260 LET C$=STR$ (M2+N2)
270 PRINT TAB (6-LEN A$);A$;TAB (12-LEN B$);B$;TAB (18-LEN C$);C$;
280 NEXT M
290 NEXT N
The line notes are:
20-30: Save table of squares.
50: Adjusted loop limits.
60: Operation moved to outer loop.
70: Adjusted loop limits.
90-110: “Direct method.” A = M ** 2 – N ** 2. B = 2 * M * N. C = M ** 2 + N ** 2.
130-150: Conditional swap of A and B values to make A the smaller and B the larger.
160-220: Euclid’s method for GCD.
230: Skip multiples.
240-270: Right-justified numbers.
The program runs on the T/S 1000 without additional memory.
Randolph J. Herber
[address omitted]
Wheaton, IL
Ed.—For 1K RAM, RUN in FAST. When the display stops with error code 4, hit CONT and ENTER. For more than 1K add:
265 SCROLL
and RUN in SLOW.