The object of this game, rewritten from one published by Creative Computing, is to get the numbers in ascending order from left to right. When the computer asks for number to reverse, enter how many numbers from left to right you wish to reverse. For example:
YOUR LIST IS NOW: 2 3 4 5 1 6 7 8 9
Reversing 4 numbers gives you:
5 4 3 2 1 6 7 8 9
Now reversing 5 numbers will win:
1 2 3 4 5 6 7 8 9
Line 30 sets N=9. The computer accepts only numbers between 0 and N. To change the length of the list, change N in line 30. If you enter 0 the computer sets up a new list (line 250). You can change line 250 to 250 IF R=0 THEN STOP so entering 0 ends the program.
30 LET N=9
40 DIM A(N)
50 LET T=0
100 LET A(1)=RND(N-1)+1
110 FOR K=2 TO N
120 LET A(K)=RND(N)
130 FOR J=1 TO K-1
140 IF A(K)=A(J) THEN GO TO 120
150 NEXT J
160 NEXT K
210 GO SUB 600
220 PRINT
230 PRINT "NO. TO REVERSE"
240 INPUT R
250 IF R=0 THEN GO TO 50
260 IF R=N OR R<N THEN GO TO 300
265 PRINT
270 PRINT "OOPS TOO MANY"
280 GO TO 240
300 LET T=T+1
310 FOR K=1 TO R/2
320 LET Z=A(K)
330 LET A(K)=A(R-K+1)
340 LET A(R-K+1)=Z
350 NEXT K
360 GO SUB 600
400 FOR K=1 TO N
410 IF NOT A(K)=K THEN GO TO 220
420 NEXT K
500 PRINT
505 PRINT
510 PRINT "YOU WON IN ";T;" MOVES"
520 PRINT
530 PRINT "TRY AGAIN? (Y OR N)"
540 INPUT A$
550 IF A$="Y" THEN GO TO 50
555 PRINT
560 PRINT
565 PRINT
568 PRINT
570 PRINT ,"OK HOPE YOU HAD FUN"
580 STOP
600 CLS
605 PRINT
610 PRINT ,"REVERSE"
620 PRINT
630 PRINT
640 PRINT "YOUR LIST IS NOW:"
650 PRINT
660 PRINT
670 FOR K=1 TO N
680 PRINT " ";A(K);
690 NEXT K
700 PRINT
705 PRINT
710 RETURN
Syntactic Sum: -13568, 4K
CHANGES TO RUN REVERSE ON 8K ROM
Reverse will not fit in 1K RAM on an 8K machine. With larger RAM sizes, change these lines:
100 LET A(1)=INT (RND*10)
120 LET A(K)=INT (RND*10)
260 IF R<=N THEN GOTO 300
310 FOR K=1 TO INT R/2
You can also change the many empty PRINT lines (used in 4K machines to arrange the display) to fewer PRINT AT statements. To avoid getting 0 in your list, add:
105 IF A(1)=0 THEN GOTO 100
125 IF A(K)=0 THEN GOTO 120
To run in 8K with only 1K of RAM, try deleting the empty PRINT statements and “user-friendly” lines (like 520-570).–AZ
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.