Two Challenges of Taxman

See all articles from SYNC v1 n6
Author(s): Austin Brown
Publication: SYNC
Pub Details: SYNC v1 n6 (Volume 1, Issue 6)
Date: November/December 1981
Pages: 46-47

Taxman has been my favorite mathematical computer game since I first discovered it in the Apple Pi program library more than two years ago. (Apple Pi is the Denver area Apple users group.) Taxman is a challenging game to play. With the advent of the ZX80 came a further challenge: could Taxman be adapted from a “large” computer (Apple II) to a really small computer, the Sinclair ZX80?

Was the second challenge met? The answer is a qualified “Yes”. Here is a complete program for Taxman, reduced in size from 50 maximum to 30 maximum. Some of the nicities of user interaction are gone, but I believe that ZX80 Taxman still is an interesting, challenging game.

Before looking at the program and its lessons in compacting large programs for the ZX80, let’s play the game.

The Game

The computer will lay out the integers from 1 to a maximum which you have entered. You pick one of these numbers; Taxman gets all the remaining factors of that number. If there are no remaining factors of the number chosen, you cannot have it. When there are no remaining factors of any unchosen number, the game is over; and Taxman gets the remaining numbers. If the sum of your chosen numbers is greater than the sum of Taxman, you win.

Let’s play a simple game. First enter or LOAD the program, then RUN.

TAXMAN
YOU GET NUMBER; I GET FACTORS

This is the abbreviated introductory message.

HOW MANY(30 MAX)?

Here you choose the size of the game; let’s choose 12.

1 2 3 4 5 6 7 8 9 10 11 12
PICK A NUMBER

Let’s pick 12.

YOU GET 12
I GET 1 2 3 4 6
SCORE- YOU:12 ME:16
5 7 8 9 10 11
PICK A NUMBER

Taxman took all the factors of 12, which added up to 16. Now from the remaining numbers let’s pick 11.

NO FACTOR FOR ME,
TRY AGAIN.
5 7 8 9 10 11
PICK A NUMBER

The only factor of 11 is 1. It is already gone. Since Taxman must always get something, we cannot choose 11. Let’s try 10.

YOU GET 10
I GET 5
SCORE- YOU:22 ME:21
7 8 9 11
DONE
I GET 7 8 9 11
FINAL SCORE- YOU:22 ME:56

Since no factors remained for any remaining numbers, the game is over and the Taxman gets the balance, and Taxman wins.

Can Taxman be beaten? Play again with 12. This time start by picking 11, then 4, etc. It is not easy, but you can beat the Taxman.

The Program

Among the factors involved in writing an interactive program are personalization, on-line documentation, and interaction. What does Taxman teach us about these factors in the severely restricted environment of the 1K Sinclair ZX80?

Personalization is that aspect of an interactive program which starts with WHAT IS YOUR NAME?, then goes on to PICK A NUMBER, BOB, encourages with TERRIFIC, BOB!, chastises with COME NOW, BOB, etc. In many programs it is a frill rather than a part of the essence of the program. Out it goes! With less than 1024 bytes at our disposal, we cannot afford the space. But wait until 16K memory arrives; personalization will be back.

On-line documentation consists of the information the program gives us about itself while it is running. Ideally, this should include everything we need to know to run the program; no external manual or other printed instructions should be needed. The realities of a 1K byte machine take us a long way from the ideal. Sometimes, as in Acey Ducey (SYNC 1:16), no instructions are given. If possible, a program should at least include its name and one line of description or instruction (lines 20-30 of the program).

However, adding text to a ZX80 program can cause additional complications. Most video-oriented personal computers reserve a fixed block of memory for display; the ZX80 does not (ZX80 Operating Manual, p. 108). Therefore, if text is added which increases the maximum size of the display of a ZX80 program, the program may bomb with error code 4, even though the program itself will fit in memory. For example, run Taxman with 30 numbers, picking successively 24, 30, 14, 27, 26, 22. Now add line 605 PRINT and rerun with the same pattern. There is no longer room for the last few characters in the final display, hence the error ending.

Most interesting or useful programs for personal computers are interactive; they require some response from the user, whether data or decisions. The user must know what is expected when it is time for input; there is nothing as frustrating as an isolated question mark, much less only the cursor leaving you to wonder, “What do I do now?” Give as much information in the questions as possible. Lines 110 and 200 are much clearer than they would be if they said, “SIZE?” and “PICK.”

Ideally, any interactive program should maintain complete control over input, so that it is impossible to make an incorrect response. There is not much room for input control in 1K machine. The ZX80 helps us with the LS cursor when a number is expected. We can also check for range, as in lines 130 and 230. But what happens if zero or a negative number had been given for the game size? Would it have been better to cut the maximum size of the game in order to have more complete error checking?

Every program should have good logic and be written in an understandable way. One of the virtues of a tiny computer is that it forces the programmer to learn to write efficient programs if the program is to do anything significant. Efficient logic is not always clear logic. REMarks are important for clarity. However, REMarks take up space. One common solution is to have two versions of a program, one with REMarks for the human and one without for the computer. Note in the listing that all REMarks have line numbers ending in 5. These can be eliminated from the running version of the program if you have a 1K RAM or if you do not want to enter them.

Lines 240-350 give another lesson from Taxman about ZX80 programming. The ZX80 displays output on the TV screen only when all computation is completed. This is usually considered a disadvantage; it can be turned to an advantage when a given display may or may not be wanted. The display of the division of the spoils is always started. If there are no factors for Taxman, line 350 sends control to line 800, where the display is cleared before it is ever seen.

Program Listing

None of the REMarks are to be entered into the ZX80; they are included to show you the logic of the program.

If you use the Syntactic Sum <TM> method to verify that you have entered the program correctly, you must SAVE the program, then NEW, then LOAD before running. Taxman is too large to run with the Syntactic Sum program in memory.

  5 REM taxman for ZX80
10 DIM F(30)
15 REM introduction
20 PRINT "TAXMAN"
30 PRINT "YOU GET NUMBER; I GE
T FACTORS"
75 REM initiate
80 LET B=0
90 LET T=0
100 PRINT
110 PRINT "HOW MANY(30 MAX)?"
120 INPUT N
130 IF N>30 THEN GO TO 110
140 CLS
150 FOR I=1 TO N
160 LET F(I)=1
170 PRINT I;"#";
180 NEXT I
190 PRINT
195 REM process choice
200 PRINT "PICK A NUMBER"
210 INPUT K
220 CLS
230 IF F(K)=0 OR K>N OR K<2 THE
N GO TO 850
240 PRINT "YOU GET#";K
250 REM look for factors
255 PRINT "I GET#";
260 LET C=0
270 FOR I=1 TO K/2
280 IF F(I)=0 OR (K/I)*I<K THEN
GO TO 330
290 LET C=1
300 LET F(I)=0
310 LET T=T+I
320 PRINT I;"#";
330 NEXT I
340 PRINT
350 IF C=0 THEN GO TO 800
360 LET B=B+K
370 LET F(K)=0
430 PRINT
440 PRINT "SCORE- YOU:";B;"#ME
:";T
450 PRINT
470 FOR I=1 TO N
480 IF F(I)=0 THEN GO TO 500
490 PRINT I;"#";
500 NEXT I
510 PRINT
515 REM check for no more factors
520 FOR I=4 TO N
530 IF F(I)=0 THEN GO TO 590
540 FOR K=2 TO I/2
550 IF NOT F(K)=0 AND (I/K)*K=I
THEN GO TO 200
580 NEXT K
590 NEXT I
595 REM wrapup
600 PRINT "DONE"
610 PRINT "I GET#";
630 FOR I=4 TO N
640 IF F(I)=0 THEN GO TO 670
650 LET T=T+I
660 PRINT I;"#";
670 NEXT I
680 PRINT
690 PRINT
750 GOTO 999
795 REM no factor found
800 CLS
810 PRINT "NO FACTOR FOR ME,"
820 PRINT "TRY AGAIN."
830 GO TO 470
845 REM illegal choice
850 PRINT "WRONG,"
860 GOTO 820
999 PRINT "FINAL SCORE-##YOU:";
B;"#ME:";T
Syntactic Sum=1418

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