Two small programs from David Ahl’s collections of classic BASIC games, on one tape with a menu. In Guess the computer picks a whole number from 0 to 100 and tells you whether each guess is too high or too low, then comments on how many tries you needed. Nicomachus is the “boomerang” puzzle from the Arithmetica of Nicomachus (about A.D. 90): think of a number from 1 to 100, give its remainders when divided by 3, 5 and 7, and the program names it.
Guess carries the REM “converted from the original FOCAL program to BASIC by David Ahl, Digital”, and Nicomachus “written by David Ahl, Digital”; both were published in Ahl’s game books and reprinted in the user group listings linked below.
Program Analysis
Nicomachus uses the Chinese remainder theorem: D=70*A+21*B+15*C, reduced by 105 until it is 105 or less (lines 80–100). Line 85 is a delay loop whose IF can never be true, used to make the computer “think”. Guess is the classic loop of INPUT, compare and count.
Potential Issues
- Guess picks from 0 to 99 (
INT (RND*100)), although it says 0 through 100. - In Nicomachus, the second IF on line 120 follows a GO TO and is never reached; line 130 repeats the test, so the program works.
These copies came from a Larken disk; only the disk save and menu lines were removed, and a menu was added at the start of the tape. Tested in ZEsarUX.
Source Code
5 REM *** CONVERTED FROM THE ORIGINAL FOCAL PROGRAM TO BASIC BY
6 REM *** DAVID AHL, DIGITAL
10 CLS : PRINT "I HAVE CHOSEN AN INTEGER 0 THROUGH 100. TRY TO"
15 PRINT "GUESS MY NUMBER IN AS FEW TRIES AS POSSIBLE."
16 PRINT
20 LET C=0
22 RANDOMIZE
25 LET N=INT (RND*100)
26 REM 25 LET N=INT(RND(0)*100)
30 LET C=C+1
35 PRINT "YOUR GUESS IS ";
40 INPUT G
45 IF N=G THEN GO TO 70
50 IF G>N THEN GO TO 60
55 PRINT "TOO LOW"
56 GO TO 30
60 PRINT "TOO HIGH"
65 GO TO 30
70 PRINT "CORRECT IN",C;" GUESSES."
75 IF C>3 THEN GO TO 90
80 PRINT "YOU WERE LUCKY!"
85 STOP
90 IF C>7 THEN GO TO 100
95 PRINT "GOOD JOB."
98 GO TO 105
100 PRINT "BUT YOU SHOULDN'T NEED MORE THAN 7 GUESSES."
105 PRINT '"LET'S PLAY AGAIN"
110 PRINT "I'M THINKING OF ANOTHER NUMBER": GO TO 20
999 STOP
9989 STOP
10 REM *** WRITTEN BY DAVID AHL, DIGITAL
20 CLS : PRINT " BOOMERANG PUZZLE FROM"," ARITHMETICA OF NICOMACHUS -- A.D. 90!"
30 PRINT : PRINT "PLEASE THINK OF A NUMBER BETWEEN 1 AND 100.": PRINT
40 PRINT "GOT IT? O.K. LET'S START....."
50 INPUT "YOUR NUMBER DIVIDED BY 3 HAS A REMAINDER OF> ";A
60 INPUT "YOUR NUMBER DIVIDED BY 5 HAS A REMAINDER OF> ";B
70 INPUT "YOUR NUMBER DIVIDED BY 7 HAS A REMAINDER OF> ";C
80 PRINT : PRINT "LET ME THINK A MOMENT": LET D=70*A+21*B+15*C
85 FOR I=1 TO 1000: IF A*B*C=105 THEN GO TO 90: NEXT I
90 IF D<=105 THEN GO TO 110
100 LET D=D-105: GO TO 90
110 PRINT AT 13,0;"YOUR NUMBER WAS",D: INPUT "RIGHT?> "; LINE A$
120 IF A$="YES" THEN GO TO 150 : IF A$="NO" THEN GO TO 160
130 IF A$="NO" THEN GO TO 160
140 PRINT AT 9,0;"EH? I DON'T UNDERSTAND '";A$;"'. "'"%%%%%% TRY 'YES' OR 'NO'. %%%%%%": GO TO 110
150 CLS : PRINT "HOW ABOUT THAT!!": GO TO 170
160 CLS : PRINT "I FEAR YOUR ARITHMETIC IS IN ERROR."
170 PRINT : PRINT : PRINT "LET'S TRY ANOTHER.": GO TO 30 : STOPNote: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.

