(Ebook - Commodore Computers) Impossible Routines For The c64
(Ebook - Commodore Computers) Impossible Routines For The c64
!iOFT§YNC
14 East 34th St.
New York, NY 10016
Prentice/Hall e
ENGLEWOOD CLIFFS, N.J. LONDON
International
NEW DELHI
RIO DE JANIERO
SINGAPORE
WELLINGTON
SYDNEY TOKYO TORONTO
Brain Games for Kids and Adults Using the Commodore 64
Includes index.
1. Computer games. 2. Commodore 64 (Computer)-
Programming. 3. Basic (Computer program language)
4. Mathematical recreations. I. Title.
GV1469.2.S7 4 1984 794.8'2 84-329
ISBN 0-13-0809 38-1
84 85 86 87 88 89 90 91 92 93 94 1 2 3 4 5 6 7 8 9 10
This small book of fun and games is dedicated to
my children Margot, Blake, and James,
who have been a big help.
Limits of Liability and
Disclaimer of Warranty
The author and publisher of this book have used their best efforts in
preparing this book and the programs contained in it. These efforts include the
development, research, and testing of the programs to determine their
effectiveness. The author and the publisher make no warranty of any kind,
expressed or implied, with regard to these programs, the text, or the
documentation contained in this book. The author and the publisher shall not be
liable in any event for claims of incidental or consequential damages in
connection with, or arising out of, the furnishing, performance, or use of the text
or the programs. The programs contained in this book and on any diskettes are
intended for use of the original purchaser-user. The diskettes may be copied by
the original purchaser-user for backup purposes without requiring express
permission of the copyright holder.
Note to Authors
Do you have a manuscript or a software program related to personal
computers? Do you have an idea for developing such a project? If so, we
would like to hear from you. The Brady Co. produces a complete range of
books and applications software for the personal computer market. We
invite you to write to David Culverwell, Publishing Director, Brady
Communications Company, Inc., Bowie, Maryland 20715.
Trademarks of Material
Mentioned in This Text
vii
Your Number Is Up . .. .. .. .. .. .. .. .. .. .. .. .. . . . . .. .... .. .. . .. .. . 105
Cryptic..... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
Human Arithmetic .. . . .. . . . .. .. . . . .. .. .. . . . . .. .. .. .. . .. . .. .. . .. .. . 112
Jugs.................................................................. 117
Chapter V
Geometry Games . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
Detonation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
Quest . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
Trek.................................................................. 132
U-Boat ............................................................... 138
Warp................................................................. 143
Chapter VI
Algebra Games . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
Monkey Puzzle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
Obscure Ages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
More Obscure Ages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
Much More Obscure Ages .. .. .. . .. .. .. .. .. .. .. .. .. .. . . .. .. .. .. . 158
Product and Sums . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
Rally................................................................. 166
Chapter VII
Root Finders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
Fixed-Point . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
Bracket . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
Appendix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
Disk Load . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
Loader............................................................... 182
Loader (With Music)............................................. 186
Music Maker....................................................... 192
Index......................................................................... 197
Instructions For Operating The Prerecorded Floppy Disk...... 203
Instructions For Making A Back-up Copy Of Your Brain
Games Diskette . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
viii
PREFAC E
WARNING! These games may be hazardous to your peace of mind! You
will not find the usual ZAP, ZING, and BOOM of the arcade games here.
These are quiet, peaceful, challenging games of concentration and mental
skill that can be played between just you and your computer, or a group of
your friends can gather around and challenge the computer to battle. The
games can be a lot of fun, but are you up to the challenge?
Can you keep your cool when lost in a four-dimensional time warp
and your fuel supply is running low?
Will you be able to locate the pirates' treasure before the pirates find
it and use you to scrub the barnacles off their ship?
How are you at finding your way around a three-dimensional chess
board or cooly deducing the location of a bomb in a three-dimensional
building of one million rooms before the bomb detonates?
Can you outwit your computer at games of strategy and logic?
These games are meant to entertain you. While you are having fun,
you will learn something about programming and mathematics.
First of all, a lot of good stuff is crammed into very few lines of code.
The reason for keeping the codes so tight and concise is that it minimizes
the risk of typographical errors occurring while you enter the code on
your machine. At the same time, it is not a great chore to enter 30 or 40
lines, and yet where else can you derive so much pleasure from so little an
investment of your time?
Second, there are useful programming tips that illustrate short cuts
in programming. And last but not least, the solutions to the games
demonstrate some everyday, practical mathematics. If you are not
familiar with programming, then you will find that the short programs in
this book will serve as an introduction to programming techniques.
You don't have to use mathematics to solve the games. My children,
aged 10, 14 and 1 7 have enjoyed playing the games for hours. The
youngest uses the technique "by guess and by golly". The middle one
delights in "breaking" into the execution of a program, and since the
computer can not lie, he obtains the answers from the computer in
response to print commands. However, if you are studying mathematics
at the high school or university level, or you simply enjoy solving
mathematical puzzles, you will delight in the challenge of trying to solve
these games in the quickest and most elegant fashion.
In many cases, you are encouraged to go further and to seek answers
to questions or problems that are pointed out in the description of a
ix
program. It is my sincere hope that in these games, you will discover for
yourself something new and interesting in mathematics.
X
INTRODUCT ION
This collection of short programs has been written in BASIC for the
COMMODORE 64. The object was to keep the programs short and
snappy. Sometimes as in "SIMON", "ANAGRAMS", "ENIGMA", and
"NIM", an additional listing of a longer version of the same program is
included when there is something to be gained through the use of the
longer program. The point is that you will be able to enter a short program
in less than 10 minutes. There is less chance of your making
typographical errors with short programs but if you do make an error, it
should not be too difficult to find the error and debug your code.
The programs in this book are generally made up of three parts.
Lines 1 to 99: Code for information about the game.
Lines 100 to 999: The game, or main part of the program.
Lines 1000 to 9999: Code for audio-visual effects.
In every case, lines 100 to 999 of the listings contain the essential
part of the programs. The additional lines before 100 give information on
how to play and contain a summary of the information given in the
sections AIM OF THE GAME and HOW TO PLAY, which are placed in this
book after each listing. The code in the lines following line 999 are for
audio-visual effects. These additions make the programs more exciting to
run, but are a pain to enter! To get started, you may want to enter the
main part of the programs first. You will need to read the section on THE
CODE to make sure that any references to the audio-visual coding is
suppressed. At a later stage, you could add the extra lines. You may also
leave out all the REM statements that are included in the listings to
explain what the code is doing.
In order to keep the main part of the programs short, the use of
screen displays and graphics had to be kept to the bare essentials of
prompts and messages. The listings given in this book are identical to the
screen displays of your entered programs. If your listing does not match
the one given, there is something wrong in the entry of your code. It may
or may not be crucial, but it will serve as a warning for you to check for
possible errors in your code. If you do not want to type in these programs
yourself, you can purchase a prerecorded floppy disk, and enjoy playing
the longer versions of the games immediately.
These programs will be quite useful to beginners in programming.
They will also give you a chance to become acquainted with analytic
geometry, linear equations, quadratic equations, systems of linear and
non-linear equations, conics, Lagrange Interpolation, probability and
xi
statistics, binomial probability, binomial expansion, Pascal's triangle, the
arithmetic of complex numbers, representation of numbers in different
bases, Cartesean and polar coordinates, distances measured by different
norms, the 1-norm and the Euclidean norm. There are also games of
logic, concentration, and of course, arithmetic and algebra.
Unlike arcade games, these games do not use moving graphics. For
the most part, the display is used for prompts, answers, and messages of
praise or doom! The essential features of the games are that they develop
concentration, imagination, logic and the ability to do mental arithmetic.
The games are collected into chapters which categorize them as to
their general content. You might find it helpful to refer to the following
where the games are categorized as to their specific nature or
mathematical content.
Content Game
Algebra: MONKEY PUZZLE, OBSCURE AGES,
MORE OBSCURE AGES, MUCH
MORE OBSCURE AGES, PRODUCT
AND SUMS, RALLY
Analytic geometry: DETONATION, QUEST, TREK, U-
BOAT, WARP
Arithmetic: BARTER, BASE, CRYPTIC, HUMAN
ARITHMETIC, JUGS, PRODUCT
AND SUMS, RALLY, YOUR NUM-
BER IS UP
Cartesian coordinates: DETONATION, QUEST, TREK, U-
BOAT, WARP
Complex numbers: HUMAN ARITHMETIC
Concentration and memory: CONCENTRATION, FLASH, KNIGHT,
KNIGHTMARE, LOOSE CHANGE,
SIMON, VERIFY
Cylindrical and polar coor- U-BOAT
dinates:
Distance measured by 1- QUEST, TREK, WARP
norm:
Euclidean distance: DETONATION, U-BOAT
Gauss elimination and lin- OBSCURE AGES, MORE OBSCURE
ear equations: AGES, MUCH MORE OBSCURE
AGES, RALLY, TREK, WARP
Lagrange interpolation: ANAGRAMS, HUMAN ARITHMETIC
xii
Content Game
Logic and strategy: INVADER, KNIGHT, KNIGHTMARE,
LOOSE CHANGE, MONKEY PUZZLE,
NIM, INVADER, SEA HUNT, TOW-
ERS OF HANOI
Number bases: BASE, NIM, TOWERS OF HANOI,
YOUR NUMBER IS UP
Probability and statistics: INVADER, PROBABILITY, SEA HUNT
Quadratic equations and DETONATION, PRODUCT AND SUMS,
non-linear equations: U-BOAT
Word games: ANAGRAMS, ENIGMA, HANGMAN,
FIND A WORD
Zeros or roots: FIXED-POINT, BRACKET
xiii
,-,_:"::-"~:_::'~-:F_:::?-:?,-'~"F~,,~:;--;;-,,::;,::~-i'A'::_:-:,_::;:,:;~'::,:::_:_;:;-;::;:,~>,:~;::_', :-;_;;--:-t-: -::,_:x::i:\1:;;: :~:,:,-:,:::'~('!'-:.,~- '::' :;~- -:~:
etif tER I
COill liJll'f lll\..'f iOll' ·
.··c;A.,MES
2 CONCENTRATION GAMES
''Concentration''
10 PRINT "a":PRINT:PRINT "INSTRUCTIONS?
PRESS Y OR N":PRINT
20 GET AS:IF A$="" THEN 20
30 IF AS<>"Y"THEN 100
40 PRINT "NUMBERS ARE HIDDEN IN A SQUARE
FULL OF *"
50 PRINT "YOU MUST FIND PAIRS OF MATCHIN
G NUMBERS."
60 PRINT "YOUR TRIES ARE COUNTED AND YOU
R GOAL IS H
''Concentration''
AIM OF THE GAME
This is a game that tests your concentration and memory. An array of
S rows and S columns of asterisks(*) is set up. You decide on the size of
the array by entering a number 1 ,2,3 or 4 in response to a prompt. The
value of S is twice the number that you choose to enter. The numbers 1 to
S are randomly distributed in each of the rows, but are hidden behind the
asterisks. You are prompted to enter coordinates, (row I and column J) of
two asterisks. The numbers behind your chosen asterisks are displayed. If
you have selected a matching pair, they remain showing and you score a
hit. If you fail to match a pair, your selection is covered up by asterisks
and you try again. The object of the game is to match up all the pairs
possible in the fewest number of tries.
Luckily the computer does not get to have a turn, this is strictly a
game for you. The computer would be difficult to beat because like the
proverbial elephant, it never forgets!
HOW TO PLAY
When you run this program, you are first told
1 2 3 4
1 * 3 * *
2 * * * *
3 * * * *
4 * * * *
ENTER ROW AND COLUMN - TRY FOR A MATCH?
Suppose you enter 2, 1. The number in the second row first column is
revealed. If it is a pair, you get a message
A MATCHING PAIR!
ENTER ROW AND COLUMN- FOR EXAMPLE 1,2?
and you continue on while the matching pair remains showing. On the
other hand, if a pair does not match, you will be prompted to try again.
After a brief moment, while you memorize the numbers you turned up,
they are covered by asterisks and you are once again prompted to enter
your choice of coordinates.
When you have matched all the numbers that can be paired, (in this
case there are only eight pairs), you will be given the message
YOU SOLVED THE GAME IN T MOVES
where T will be the number of your tries. You are then invited to play
again or to quit. To quit at any time, enter the pair -1 ,-1.
THE CODE
The program checks that you enter two different number pairs. It
also checks that you enter the coordinates of a position that are not
already matched. These checks are in lines 246, 250, 270 and 275.
In setting up the game, the numbers 1 to S are jumbled up on each
row. The game would be more difficult if the numbers were randomly
located anywhere on the array. This would mean that a particular number
might occur more than once in any given row. This is a fairly difficult
programming exercise for a beginner, but I urge you to try it. Even if you
do not succeed, you will have learned something about programming. My
suggestion is to set up a routine to exchange pairs of numbers in the
array A, and then thoroughly mix them up.
One other challenge I would like to leave with you is to design a
subroutine in which the computer takes a turn when you miss. It would be
easy to design a few lines that cause the computer to look at random
locations. But what I had in mind was that the computer could use any
information revealed in previous turns. You will then be able to play
extremely challenging games with your computer, which would never miss
using any relevant information.
''FLASH'' 7
''Flash''
10 PRINT "~":PRINT:PRINT "INSTRUCTIONS?
PRESS Y OR N":PRINT
20 GET A$:IF A$="" THEN 20
30 IF AS<>"Y" THEN 100
40 PRINT "THIS GAME IMPROVES THE SPEED 0
F YOUR"
50 PRINT "READING. STARTING WITH A SINGL
E LETTER,"
50 PRINT "A STRING IS FLASHED ON THE SCR
EEN FOR A"
70 PRINT "MOMENT. YOU MUST ENTER THE SAM
E STRING."
80 PRINT "IF YOU ARE RIGHT, THEN A NEW S
TRING IS"
85 PRINT "FLASHED WITH ONE EXTRA CHARACT
ER."
90 PRINT "IF YOU PREFER, YOU MAY USE NUM
BERS.":PRINT
95 INPUT "PRESS RETURN TO GO ON"; :REM TH
IS WAITS WHILE THE MESSAGE IS READ
100 PRINT "tJ"
110 PRINT "NUMBERS OR LETTERS?"
120 PRINT:PRINT "PRESS NOR L KEY"
130 GET C$: IF C$="" THEN 130
140 FOR I=1 TO 24:REM THIS LIMITS THE LE
NGTH OF THE STRING TO 24
150 PRINT "WORKING ... ":REM FOR LONGER ST
RINGS THE SET UP CAN TAKE A MOMENT
155 LET A$="":REM STARTS OFF WITH AN EMP
TY STRING EACH TIME
160 FOR J=1 TO I
170 IF C$="N" THEN 210
180 LET S=INT(26*RND(0))+ASC("A")
190 LET A$=A$+CHR$(S) :REM CREATES A STRI
NG OF RANDOM LETTERS OF LENGTH I
200 GOTO 220
210 LET A$=A$+RIGHT$(STR$(INT(10*RND(0))
) ,1) :REM STRING OF NUMBERS, NO BLANKS
220 NEXT J
230 PRINT "~"
8 CONCENTRATION GAMES
''Flash''
AIM OF THE GAME
This program tests your ability at reading and remembering a
sequence of letters or numbers that are flashed on the screen. You are
asked for your choice of letters or numbers. Then starting with a single
character and increasing by one character each time, a randomly
generated sequence is flashed for a short time on the screen. Each time
you enter a correct sequence another sequence with an additional
character is flashed for you.
It is very difficult to get more than 10 characters correct.
Psychologists have found that the average person can usually recall about
7 characters. This program stops at 24 characters, but it is not difficult
to increase this limit by changing the limit in line 140.
This program is designed to increase your concentration and your
reading speed. You will find it very challenging.
HOW TO PLAY
When you run this program the screen clears and the following
message appears.
NUMBERS OR LETTERS?
PRESS N OR L KEY
Suppose you press the L key. Immediately the screen clears, the word
WORKING ...
appears momentarily (when you are up to sequences that are 24
characters in length it takes a few seconds to construct the sequence).
Then you are prompted with the message
PRESS A KEY WHEN READY
The reason for this is that you can blink your eyes, clear your throat,
scratch the itchy spot on your nose and generally prepare yourself for the
flash. When you are ready you press any key. A single letter is flashed on
the screen and disappears. Let us say it was
w
Then you are prompted with the message
TYPE WHAT YOU JUST SAW AND PRESS RETURN
You type the letter W and then enter it. The message
CORRECT
10 CONCENTRATION GAMES
is displayed for a short time, then back to WORKING ... and the whole
thing is repeated except that the sequence will contain two characters this
time. Each time you enter a correct sequence the next sequence will
contain one more character than the previous one.
If you should happen to enter an incorrect sequence, as we all do
eventually, you will be given the message
WRONG IT IS ABCXYZ
(whatever the sequence was)
AGAIN? PRESS Y OR N
If you feel up to playing another game, press the Y key. Otherwise,
press any other key to quit for a well deserved rest.
You may feel that a little more time is needed in order to view the
sequence and memorize it. All you need to do is alter the statement in line
270 to 200 + 300*1 or something like that. Do not make the pause too
long or you will defeat the purpose of the game.
Happy flashing!
"KNIGHT" 11
''Knight''
10 PRINT "O":PRINT:PRINT:PRINT " INSTRU
CTIONS? PRESS Y OR N"
15 GET A$:IF A$="" THEN 15
20 IF A$<>"Y" THEN 110
25 PRINT "~":PRINT:PRINT
30 A$="• • • • ":B$=" • • • •":E$="-----
___ , .· R$=" -------- "·. T$="1" .· Y$-"l"
-
35 PRINT TAB(9) ;"ABCDEFGH":PRINT TAB(9);
R$
40 FOR 1=1 TO 8:PRINT TAB(5);I;Y$;
45 LET C$=A$:IF I-2*INT((I/2))=0 THEN C$
=B$
50 PRINT C$;T$:NEXT !:PRINT TAB(9);E$
55 PRINT:PRINT "THIS GAME USES A CHESS B
OARD"
60 PRINT "A LETTER AND A NUMBER ARE USED
TO MARK EVERY POSITION ON THE BOARD"
65 PRINT "THE GAME IS TO MOVE A KNIGHT F
ROM ONE"
70 PRINT "POSITION TO ANOTHER IN AS FEW
MOVES AS"
75 PRINT "POSSIBLE (MOVES ARE IN 1-2 COM
BINATIONS)"
90 INPUT "PRESS RETURN TO START";
110 LET C=0
120 PRINT "0"
125 PRINT:PRINT"ENTER MOVE IN THE FORM L
ETTER NUMBER":PRINT "ENTER -1 TO STOP"
130 LET A=INT(8*RND(0))+ASC("A")
140 LET B=INT(8*RND(0))+ASC("A")
150 LET M=INT(8*RND(0))+ASC("1")
160 LET N=INT(8*RND(0))+ASC("1")
165 IF A=B AND M=N THEN 130
170 PRINT: PRINT "MOVE FROM ";CHR$(A) ;CHR
$(M);" TO ";CHR$(B) ;CHR$(N)
180 LET C=C+1
190 PRINT C;" ";CHR$(A);CHR$(M) ;"TO";
200 INPUT A$
201 IF VAL(A$)=-1 THEN 275
205 LET D$=LEFT$(A$,1)
12 CONCENTRATION GAMES
''Knig ht''
AIM OF THE GAME
This is a game of concentration and teaches you to visualize a
situation in your mind. This ability is essential in the study of
mathematics. To start with, however, you might prefer to use a chess
board with the letters A to H marked across the board from left to right,
and the numbers 1 to 8 marked on the edge of the board starting with 1
at the bottom and ending with 8 at the top.
The game is to move a chess piece, called a knight, from one given
location on a chess board to another given location. The knight moves in a
peculiar way crossing three squares each move. It can move in any
combination of 1 up or down and 2 across, or 2 up or down and 1 across.
Your moves are checked and counted. The idea is to try to get to your
final destination in the least number of moves. However, it is a bit like
running a marathon because there is no penalty for being slow. The idea
is to stick with it until you finish.
HOW TO PLAY
When you run this program, the screen clears and you are given a
message like
ENTER MOVE IN THE FORM LETTER NUMBER
ENTER -1 TO STOP
MOVE FROM C2 TO C4
1 C2 TO ?
Your entry must be in a string, first a letter and then a number. Your
move will be checked. If it is not a valid move, you will be asked to repeat
the move. Suppose you were to enter 04. On the screen you would see
2 04 TO ?
Suppose you now entered C4 (wishful thinking!). You would get the
message
INVALID MOVE
3 04 TO ?
Now let us go back to C2. We will not fool around any more. The message
is
4 C2 TO ?
We enter E3. The message is
5 E3 TO ?
14 CONCENTRATION GAMES
THE CODE
Lines 10 to 90 may be omitted. They only give some instructions on
how to play the game. The INPUT in line 90 halts the execution so that the
screen can be read.
Could you design a subroutine that determines the solution in the
minimum number of moves? You could then have the computer print out
that solution.
''KNIGHTMARE'' 15
''Knightmare''
10 PRINT "a":PRINT:PRINT "THIS IS A 3-D
VERSION OF KNIGHT"
20 PRINT "YOU SHOULD PLAY KNIGHT BEFORE
TACKLING"
30 PRINT "THIS HORROR!"
40 PRINT:PRINT "MOVES MUST BE ENTERED AS
LETTER NUMBER"
50 PRINT "LETTER LIKE":PRINT TAB(4) ;"E5G
":PRINT
60 PRINT "EVERY COORDINATE MUST CHANGE"
70 PRINT "THE TOTAL CHANGE MUST BE 6":PR
INT
90 INPUT "PRESS RETURN TO START";
110 LET C=0
120 PRINT "a"
125 PRINT:PRINT "ENTER MOVE IN THE FORM
'E5G' LETTER":PRINT "NUMBER LETTER"
126 PRINT "ENTER -1 TO STOP":PRINT
130 LET A=INT(8•RND(0))+ASC("A")
140 LET B=INT(8·RND(0))+ASC("A")
145 LET O=INT(8•RND(0))+ASC("A")
150 LET M=INT(8·RND(0))+ASC("1")
160 LET N=INT(8·RND(0))+ASC("1")
165 LET P=INT(8·RND(0))+ASC("A")
166 LET Z=ABS(A-B)+ABS(M-N)+ABS(O-P)
167 IF Z-2·INT(Z/2)<>0 THEN 130
170 PRINT "MOVE FROM ";CHR$(A) ;CHR$(M) ;C
HR$(0) ;"TO ";CHR$(B) ;CHR$(N) ;CHR$(P)
180 LET C=C+1
190 PRINT C;" ";CHR$(A) ;CHR$(M) ;CHR$(0);
"TO";
200 INPUT A$
201 IF VAL(A$)=-1 THEN 275
205 LET D$=LEFT$(A$,1)
206 LET E$=MID$(A$,2,1)
207 LET F$=RIGHT$(A$,1)
210 IF A=ASC(D$) OR M=ASC(E$) OR O=ASC(F
$) THEN 300
215 IF ABS(A-ASC(D$))+ABS(M-ASC(E$))+ABS
(0-ASC(F$))<>6 THEN 300
16 CONCENTRATION GAMES
''Knightm are''
AIM OF THE GAME
This is a three-dimensional version of the chess game called
"KNIGHT". You should try the standard two-dimensional game "KNIGHT"
before tackling this game. As the name implies, you might have trouble
going to sleep after playing this horror.
HOW TO PLAY
You are given a starting point and a finishing point on a three-
dimensional chess board. The locations are given by a letter A to H,
followed by a number 1 to 8, and then another letter A to H. Your knight
can move a total of six squares in any combination of (2,2,2), (4, 1, 1) or
(1 ,2,3). By any combination, I mean for instance, in the (1 ,2,3) move, any
one of the coordinates can be changed by 1 unit, another by 2 units and
the remaining coordinate by three units. A typical run would go like this.
You are given the prompt
ENTER MOVE IN THE FORM 'E5G' LETTER
NUMBER LETTER
ENTER -1 TO STOP
MOVE FROM G5A TO E4B
1 G5A TO ?
Every coordinate must alter. So suppose you enter the move F7D. You
would get the message
1 G5A TO ? F7D
2 F7D TO ?
Now you can enter E4B and you are home in 2 moves!
You must enter your moves in a string containing all the three new
coordinates in the format, letter, number and then letter.
Your moves are checked each time for validity. Every coordinate
must change and the total change must be precisely 6. When you get
home you are prompted to play another game or to quit.
-3, -2 by adding. This means we can get home in just two moves, and the
moves made above in HOW TO PLAY accomplish this.
You will notice that I only used the (1, 2, 3) move, which I think
should be the only one allowed. However, you might find the game
difficult enough without adding this restriction! If you would like a more
difficult challenge, you could limit yourself to the (1, 2, 3) combinations,
or even add lines to the program to prohibit any other move. For instance,
you might add the lines
216 LET X=ABS(A-ASC(D$))
217 LET Y=ABS(M-ASC(E$))
218 LET Z=ABS(O-ASC(F$))
219 IF X=Y OR X=Z OR Y=Z THEN 300
You will notice that in lines 166 and 167 I had to add (as an
afterthought) the limitation that the difference in start and finish
positions could not be odd. No such restriction was needed in the two-
dimensional game. Can you work out why this restriction is necessary?
"SIMON" 19
''Simon''
100 LET B$=""
110 PRINT "Q":PRINT:PRINT" THIS GAME 0
F SIMON TESTS YOUR MEMORY"
120 PRINT "WOULD YOU LIKE NUMBERS OR LET
TERS? PRESS THE KEY N OR L"
130 GET A$:IF A$="" THEN 130
135 IF A$<>"N" AND A$<>"L" THEN 110
140 LET I=1
150 PRINT "l:J"
160 IF A$="N" THEN LET B$=LEFT$(B$,I-1)+
RIGHT$(STR$(10*RND(0)) ,1)
170 IF A$="L" THEN LET B$=LEFT$(B$,I-1)+
CHR$(26*RND(0)+ASC("A"))
180 FOR J=1 TO I
190 LET S$=MID$(B$,J,1):PRINT S$;
195 IF A$="N" THEN N=VAL(S$)
196 IF A$="L" THEN N=ASC(S$)-ASC("A")
200 FOR T=1 TO 500:NEXT T
210 NEXT J
220 PRINT "l:J":PRINT:FOR G=0 TO 10*RND(0)
+4:GET S$:NEXT:REM PREVENTS CHEATING
230 PRINT "ENTER THE SAME ";
235 IF A$="N" THEN PRINT "NUMBERS"
240 IF A$="L" THEN PRINT "LETTERS"
250 GOTO 1000
260 PRINT:PRINT "WRONG. IT IS"
265 FOR G=0 TO 10:GET S$:NEXT:REM: ERASE
S ANY ACCIDENTAL KEY PRESSES
270 PRINT LEFT$(B$,I)
275 IF I>1 THEN PRINT "YOUR SCORE WAS ";
I-1
280 PRINT "ANOTHER TURN? PRESS Y OR N"
290 GET A$:IF A$="" THEN 290
300 IF A$="Y" THEN 100
305 STOP
310 PRINT:PRINT "RIGHT ON"
320 FOR T=1 TO 2000:NEXT T
330 LET I=I+1
340 GOTO 150
1000 REM:CHECKS EACH ENTRY
20 CONCENTRATION GAMES
''Simon''
(Long Version)
10 REM: THE HI/LO FREQUENCIES FOR THE NO
TES ARE READ FROM DATA
20 REM:SET UP ORGAN
25 FOR I=54272 TO 54296:POKE I,0;NEXT I:
REM:THIS SETS ALL VOICE QUANTITIES TO 0
30 POKE 54296,15:REM SETS VOLUME TO LOUD
EST
35 FOR I=54277 TO 54291 STEP 7:POKE I,19
0:POKE I+1,255:NEXT:REM:SET SYNTHESIZER
40 PRINT "~":PRINT:PRINT" NEED INSTRU
CTIONS? PRESS Y OR N"
45 GET A$:IF A$="" THEN 45
50 IF A$<>"Y" THEN 100
55 PRINT:PRINT "WE GIVE SOUNDS TO THE NU
MBERS 0 TO 9"
60 PRINT:PRINT "THEY ARE:":PRINT
70 FOR N=0 TO 9:PRINT N:"GOSUB 8000
75 NEXT N
80 PRINT:PRINT:PRINT "LETTERS SOUND LIKE
THE FOLLOWING":PRINT
85 FOR N=0 TO 25:PRINT CHR$(ASC("A")+N);
:GOSUB 8000
90 NEXT N
100 PRINT "~":PRINT:PRINT" THIS GAME 0
F SIMON TESTS YOUR MEMORY"
120 PRINT "WOULD YOU LIKE NUMBERS OR LET
TERS? PRESS THE KEY N OR L"
130 GET A$:IF A$="" THEN 130
135 IF A$<>"N" AND AS<>"L" THEN 110
140 LET I=1
150 PRINT "~"
160 IF A$="N" THEN LET B$=LEFT$(B$,I-1)+
RIGHT$(STR$(10*RND(0)),1)
170 IF A$="L" THEN LET B$=LEFT$(B$,I-1)+
CHR$(26*RND(0)+ASC("A"))
180 FOR J=1 TO I
190 LET S$=MID$(B$,J,1) ;PRINTS$;
195 IF A$="N" THEN N=VAL(S$)
22 CONCENTRATION GAMES
''Sinto n''
AIM OF THE GAME
We have all played "Simon Says" or "Follow the Leader" at some
time or other in our lives. This game provides two versions of Follow the
Leader. You have your choice between numbers or letters. A sequence is
displayed one character after another. At first, the sequence consists of a
single character. After a short period of time, the sequence vanishes from
sight, but hopefully, not from your memory, and you are asked to enter
the same sequence. If you are correct, the same sequence is repeated
with an extra character tacked on to the end.
HOW TO PLAY
When you run this program you are given the prompt
THE GAME OF SIMON TESTS YOUR MEMORY
WOULD YOU LIKE NUMBERS OR LETTERS?
PRESS THE KEY N OR L
You press the N key if you want numbers or the L key if you want a
sequence of letters. You should find numbers easier since the choice for
each member of the sequence is only ten possibilities. Suppose you press
the L key. Immediately a single letter appears in the top left hand corner
of the screen, say
B
This vanishes in about Y2 a second. You are then prompted with the
message
ENTER THE SAME LETTERS
Suppose you enter the letter B. The message
RIGHT ON
is displayed for a few seconds and then the sequence is repeated with an
additional letter. In this case it turned out to be BA followed by BAG,
followed by BAGM and so on.
This is a very demanding game and requires tremendous
concentration. In some respects it is much easier than "FLASH", since the
same sequence is repeated over and over. But this is the very aspect that
makes this game so mentally exhausting.
When you finally make a mistake, unintentional or not, you get the
message
"SIMON" 25
WRONG. IT IS
8AGMP
(or whatever the actual sequence was)
YOUR SCORE WAS 4
ANOTHER TURN? PRESS Y OR N
If you want to quit press Nor any key other than Y. If you wish to quit
during the game, press the key RUN/STOP in response to a prompt.
THE CODE
The string variable 8$ which stores the sequence is initialized to an
empty string in line 100. In lines 160 and 170, additional characters are
added to the string 8$ on the right hand end. Unfortunately, strings of
numbers like STR$(2) would be stored as" 2" and not "2". The blank is
stripped away in line 160, by using the RIGHT$( ... , 1) function.
Since the GET command only reads in one key press at a time and
your keyboard has a memory buffer which stores key presses, lines 220
and 265 are included to prevent cheating and an accidental response to
the prompt in line 280 about quitting.
In the long version, the lines before 100 set up an organ-like sound
and demonstrate the sounds given to each letter and number. The
subroutine at line 8000 plays the notes by setting the high and low
frequencies and turning on the voices with the sawtooth waveform (33).
After the duration in line 8030, the voices are turned off by changing the
waveform to 0.
The data in the lines after line 9000 contain the high and low
frequencies of the scale of notes used in the program.
If desired, you could store the frequencies of the twenty six notes in a
matrix A(25,1). This removes the slight delay in playing the notes. You
would need to make the following changes.
5 DIM A(25,1)
10 FOR I=0 TO 25:FOR J=0 TO 1 :READ A(
I , J ) : NEXT J , I
You would delete line 8006 and change 8010 to
8010 for V=54272 TO 54286 STEP 7:POKE
V+1,A(N,0) :POKE V,A(N,1) :NEXT V
The reason I did not use this was because if you use the DISK LOAD
and LOADER programs in the Appendix, an error is caused by the
dimension statement in line 5 and automatic execution is aborted.
28 WORD GAMES
''Anagrams I''
10 PRINT"C":PRINT:PRINT "INSTRUCTIONS? P
RESS Y OR N":PRINT
20 GET A$:IF A$="" THEN 20
30 IF AS<>"Y" THEN 85
40 PRINT "THIS GAME GIVES YOU A JUMBLED
STRING OF "
50 PRINT "LETTERS AND IT IS YOUR JOB TO
FIND THE
60 PRINT "HIDDEN WORD.THE STRING ROMST,F
OR EXAMPLE"
70 PRINT "IS A SCRAMBLED VERSION OF STOR
M."
80 PRINT:INPUT "PRESS RETURN TO START";
85 FOR L=54272 TO 54296:POKE L,0:NEXT:PO
KE 54296,15:REM SETS UP VOICES
90 FOR I=1 TO 3:V=54269+7*I:POKE V+1,190
:POKE V+2,250:NEXT
95 PRINT "t:l"
100 LET G=INT(6*RND(0)) :REM CHOOSES WORD
LIST
105 ON G GOTO 120,130,140,150,160
110 LET A$="ALLYBAILCHITDIMEDIGITFLIRTGR
AINHOUSEFIDGETHOURLYLININGNOZZLE"
115 LET A$=A$+"MOVABLEOPINIONPARTNERRECO
VER"
119 GOTO 200
120 LET A$="RILETORNCLIPPOURFIFTHSURLYSL
OTSARGUESLOWLYFIRMLYGROWTHMENACE"
125 LET A$=A$+"FIGURESTRUMPETSMARTENBAST
ION"
129 GOTO 200
130 LET A$="FROGHALFMASTRENTWHEELTRUSTST
UFFSCRUBSCRIPTREBORNPUBLICMUTTER"
135 LET A$=A$+"INTRUDEHAUGHTYGIRAFFEENCH
ANT"
139 GOTO 200
140 LET A$="GUSHHAILLOVERENDWHARFTRULYST
UDYSCREWSCREENREALTYPUCKERMUTINY"
145 LET A$=A$+"INSTANTHATRACKGHOSTLYDEVE
LOP"
"ANAGRAMS I" 29
OSUB 9000
460 GOTO 350
470 PRINT:PRINT "AGAIN? PRESS Y OR N"
480 GET AS:IF A$="" THEN 480
490 IF AS="Y" THEN 95
500 STOP
9000 REM PLAYS MUSIC
9010 RESTORE:IF Z=0 THEN 9020
9015 FOR I=1 TO 7*5:READ D:NEXT
9020 FOR I=1 TO 3:READ H(I),L(I):NEXT I:
READ D
9025 FOR I=1 TO 3:POKE 54269+7*I,33:NEXT
9030 IF D=-1 THEN 9080
9040 FOR I=1 TO 3:V=54266+7*I:POKE V,H(I
) :POKE V-1, L (I) :NEXT I
9050 FOR T=1 TO D:NEXT T
9060 GOTO 9020
9080 FOR I=1 TO 3:POKE 54269+7*I,0:NEXT:
REM TURNS OFF NOTE
9090 RETURN
9900 DATA 17,37,12,216,10,205,400
9910 DATA 14,107,10,205,8,147,400
9920 DATA 12,216,10,205,7,53,400
9930 DATA 10,205,8,147,7,53,400
9940 DATA -1,-1,-1,-1,-1,-1,-1
9950 DATA 38,126,28,214,9,159,400
9960 DATA 28,214,28,214,12,32,100
9970 DATA 32,94,25,177,12,216,100
9980 DATA 28,214,24,63,9,159,100
9990 DATA -1,-1,-1,-1,-1,-1,-1
Note: The symbol t.:l represents SHIFT CLEAR/HOME.
"ANAGRAMS I" 31
BOW TO PLAY
When you run this program a scrambled word containing from 4 to 7
letters is displayed in this fashion
FHAWR
ENTER THE UNSCRAMB LED WORD
ENTER . TO QUIT
After you enter your solution to the anagram, it is compared with the
correct word and the message
RIGHT ON! NOW TRY THIS
or
WRONG! TRY AGAIN
appears. If you are right a new anagram is posed. If you were wrong, the
same anagram is repeated.
If you get stuck on a word, enter a period (.) when prompted to enter
the answer. The program will respond with the message
THE WORD IS WHARF (or whatever it is)
AGAIN? PRESS Y OR N
If you press the Y key another scrambled word is given to you. If you
press the key N, the program will stop.
32 WORD GAMES
: Z= 1 : GOSUB 9000
440 GOTO 100
450 PRINT:PRI NT "WRONG! TRY AGAIN":Z =0:G
OSUB 9000
460 GOTO 510
470 PRINT:PRI NT "AGAIN? PRESS Y OR N"
480 GET A$:IF A$="" THEN 480
490 IF A$="Y" THEN 95
500 STOP
510 PRINT:PRI NT "WANT SOME HELP? PRESS Y
OR N"
520 GET Z$:IF Z$="" THEN 520
530 IF Z$<>"Y" THEN 360
540 LET C=C+1
550 PRINT:PRI NT "THE WORD STARTS WITH":P
RINT
560 PRINT TAB(5) ;LEFT$(E$ ,C)
570 GOTO 350
9000 REM PLAYS MUSIC
9010 RESTORE: IF Z=0 THEN 9020
9015 FOR I=1 TO 7*5:READ D:NEXT
9020 FOR I=1 TO 3:READ H(I) ,L(I) :NEXT I:
READ D
9025 FOR I=1 TO 3:POKE 54269+7*I ,33:NEXT
9030 IF D=-1 THEN 9080
9040 FOR I=1 TO 3:V=54266 +7*I:POKE V,H(I
):POKE V-1,L(I) :NEXT I
9050 FOR T=1 TO D:NEXT T
9060 GOTO 9020
9080 FOR I=1 TO 3:POKE 54269+7*I ,0:NEXT:
REM TURNS OFF NOTE
9090 RETURN
9900 DATA 17,37,12, 216,10,20 5,400
9910 DATA 14,107,10 ,205,8,14 7,400
9920 DATA 12,216,10 ,205,7,53 ,400
9930 DATA 10,205,8, 147,7,53, 400
9940 DATA -1,-1,-1, -1,-1,-1, -1
9950 DATA 38,126,28 ,214,9,15 9,400
9960 DATA 28,214,28 ,214,12,3 2,100
9970 DATA 32,94,25, 177,12,21 6,100
36 WORD GAMES
''Anagrams II''
(With Dints)
If you were having trouble finding the correct word for the anagrams
in the previous program, then you might prefer this version. It is the same
game, except that if you are wrong, you are then prompted with
WANT SOME HELP? PRESS Y OR N
If you press the key Y, then you are told that
THE WORD STARTS WITH
w
for the case of WHARF scrambled up as FHAWR.
After a short pause, the hint disappears and the anagram is again
presented. If you are still stuck and enter a wrong answer, and if you want
more help, you are told that the word starts with
WH
and so on. Eventually the entire word will be presented to you, but I am
sure that with a little help you will be able to solve the anagram.
38 WORD GAMES
RMSHEDGEHEIGHTJESTERLIMPETNOTICEff
165 LET A$=A$+ffMOUTHEDOILSKINPARABLEREAL
I ZEn
200 LET W=INT(4*RND(0)) :REM PICKS ONE OF
FOUR WORDS
210 LET X=INT(4*RND(0))
220 LET L=X+4:REM PICKS WORD LENGTH
230 LET P=X*(2*X+14)+W*L+1 :REM INTERPOLA
TES
240 LET B$=MID$(A$,P,L) :REM PLUCKS WORD
OUT OF A$
250 LET M=13:REM SETS LIMIT ON NUMBER OF
MOVES
255 LET L=LEN(B$)
260 LET F$=MID$(Z$,1,L)
270 GOTO 360
280 FOR I=1 TO L:REM CHECKS IF ENTERED L
ETTER IS IN THE WORD
290 IF MID$(B$,I,1)=D$ THEN LET F$=LEFT$
(F$,I-1)+D$+RIGHT$(F$,L-1)
300 NEXT I
360 PRINT ff~ff:PRINT:PRINT
370 PRINT TAB(5) ;FS:PRINT
375 IF F$=B$ THEN 430:REM CHECK IF WORD
HAS BEEN FOUND
376 IF M<1 THEN PRINT ffTHE WORD IS ff;B$:
GOTO 440:REM NO MOVES LEFT
380 PRINT M;ffMOVES TO GOff
390 PRINT:PRINT ffTYPE A LETTER USE A . T
0 QUITff:PRINT
395 LET M=M-1
396 PRINT ffLETTERS USED SO FARff:PRINT:PR
INT L$:PRINT
400 GET ZS:IF Z$=ffff THEN 400
405 LET D$=Z$
410 IF D$=ff.ff THEN PRINT ffTHE WORD IS ff;
BS:GOTO 440
415 FOR I=1 TO LEN(L$):IF D$=MID$(L$,I,1
) THEN 420
416 NEXT I
417 LET L$=L$+D$
420 GOTO 280
430 PRINT ffRIGHT ONff
440 PRINT: PRINT ffAGAIN? PRESS Y OR Nff
~----------------------------
40 WORD GAMES
''Hangman''
AIM OF THE GAME
This game is a version of the children's game, only there are no
gallows and stick-figures. It is enough to know that you only have 13
attempts to find the correct word. This is more difficult, as a result, than
"ANAGRAMS" where you not only know the length of the word, but also
which letters appear in it.
DOW TO PLAY
When you run this program you are presented with a message like
* * * * * * *
13 MOVES TO GO
TYPE A LETTER USE A . TO QUIT
LETTERS USED SO FAR
Suppose you enter the letter A, then the message is repeated with 12 in
place of 13. Now suppose you enter the letter E, then the message
becomes
11 MOVES TO GO
TYPE A LETTER USE A . TO QUIT
LETTERS USED SO FAR
AE
You continue in this fashion until you run out of moves, or you find all the
letters in the word. If you run out of moves, the word is given to you. If you
get frustrated, and want to quit, just enter a period (.) instead of a letter
and the word is given to you. In any case, you will be invited to play again,
or to quit with the prompt
AGAIN? PRESS Y OR N
If you would like to alter the number of guesses allowed, change
M= 13 in line 250 to something that suits your fancy.
This program is a very simple program with no audio-visual effects.
You might like to add your own. The usual graphics for this game is a
gallows and a stick figure which is gradually drawn with each guess that is
wrong. The program does not check repeated entries so that if you fail to
notice a letter in the used letter list and use it a second time, it is a wasted
move. It would be a simple exercise for the beginning programmer to add
lines to run a check on the entry and print a message if the letter has
already been used. Take a look at lines 280 to 300 and use that for a
42 WORD GAMES
''Find a Word''
10 PRINT "a":PRINT:PRINT "FIND A WORD IS
A GAME WHERE YOU HAVE TO "
20 PRINT "FIND WORDS HIDDEN IN A SQUARE
OF LETTERS"
30 PRINT "THERE ARE FROM 7 TO 11 WORDS,U
P AND DOWN"
40 PRINT "ACROSS AND DIAGONAL"
50 PRINT:PRINT "ENTER . TO QUIT"
60 PRINT:INPUT "PRESS RETURN TO START";
100 PRINT "~":PRINT:PRINT "GET A SNACK,
THIS WILL TAKE A MOMENT"
101 FOR I=0 TO 9:FOR J=0 TO 9:M$(I,J)="*
":NEXT J,I:REM FILLS M WITH"*"
102 LET KK=6+INT(5*RND(0)) :N=KK:REM CHOO
SES NUMBER OF WORDS
103 WL=0:REM CHECKS NUMBER OF LETTERS IN
ALL WORDS
104 FOR K=0 TO KK:REM SELECTS WORDS
105 LET G=INT(6*RND(0))
108 ON G GOTO 120,130,140,150,160
110 LET A$="ALLYBAILCHITDIMEDIGITFLIRTGR
AINHOUSEFIDGETHOURLYLININGNOZZLE"
115 LET A$=A$+"MOVEABLEOPINIONPARTNERRECO
VER"
119 GOTO 200
120 LET A$="RILETORNCLIPPOURFIFTHSURLYSL
OTSARGUESLOWLYFIRMLYGROWTHMENACE"
125 LET A$=A$+"FIGURESTRUMPETSMARTENBAST
ION"
129 GOTO 200
130 LET A$="FROGHALFMASTRENTWHEELTRUSTST
UFFSCRUBSCRIPTREBORNPUBLICMUTTER"
135 LET A$=A$+"INTRUDEHAUGHTYGIRAFFEENCH
ANT"
139 GOTO 200
140 LET A$="GUSHHAILLOVERENDWHARFTRULYST
UDYSCREWSCREENREALTYPUCKERMUTINY"
145 LET A$=A$+"INSTANTHATRACKGHOSTLYDEVE
LOP"
149 GOTO 200
44 WORD GAMES
HOW TO PLAY
There will be at least 7 words and at most 11 words hidden in the
square. You will be told how many there are. When you RUN this game it
takes about one minute to set up the puzzle. While this is going on, you
get the message
X K E s u 0 H J u H
T R u M p E T E L A
L J X B y 0 F s N u WORDS FOUND
p F L L F E p T c G
y B u L H L D E A H
0 R v s F B w R X T
T J u N T A X w B y
s u N E G R T v N A
s G z s A A B A I L
c M p F u p H K R E
It will not accept the same word twice. If you want to quit, just enter .
(a period) when asked to enter a word. The list of words is displayed and
you are prompted with
AGAIN? PRESS Y OR N
You press the key N to quit or Y to play another game.
THE CODE
This is a very long program for this book. The main difficulty was
fitting the words into the square. The words are not allowed to intersect
one another. Otherwise we would have to make sure that they intersected
in a common letter and this would be too time consuming. I made the
choice of not letting words intersect. But then it might become impossible
to locate all the words in the 10 by 10 array. By trial and error, I found
that if the chosen words had more than 65 letters in total, it might be
impossible to locate all the words in the 100 places available. So in line
255, if the total number of letters is greater than 55 (a considerable
margin for error), then a new list of words is generated. You may
experiment with the number of letters allowed by changing the limit in line
255.
Fitting the words into the square is done in lines 260 to 355. This is
the part that takes all the time in setting up the puzzle. The square M$ is
filled with "*" to start with in line 101. A random row I and column J is
selected in line 170. Lines 272 to 320 check to see which way the word
could run, forward, backward, diagonally down to the right, diagonally up
to the left, diagonally up to the right, diagonally down to the left, vertically
down or up. The vector C contains a 1 or a 0 in each of eight positions
corresponding to the above possibilities. A 0 means that that particular
choice is blocked. Line 338 chooses one of the possible ways of locating
the word. Lines 340 to 348 select the appropriate parameters and line
350 locates the word. For instance, if the word is being placed diagonally
down to the left, starting from (I,J), U would be 1 and B would be 1.
Then:
M$(1,J) = the first letter in the word B$(K)
M$(1+1,J+1) = the second letter in the word B$(K)
M$(1+2,J+2) = the third letter in the word B$(K)
"FIND A WORD" 49
If the word was BAIL and (I,J) was (3,5), then we would have
Column 5
Row 3 8
A
I
L
Finally, lines 361 to 363 fill up the spaces in M$ that still contain *'s
with randomly chosen letters. I use this loop to create a pause during the
playing of the game so that the message about how many words to go is
displayed on its own.
I did not add any audio-visual effects as I thought the listing was too
long as it was. You might like to try the following. When a word is correctly
located, it is displayed in reverse letters, or in a different color, or simply
flashes for a moment while the congratulatory music plays!
50 WORD GAMES
''Enigma I''
110 PRINT "r.J"
120 LET C=INT(25*RND(0))+1
130 LET Z=ASC("Z")
135 PRINT "ENTER YOUR MESSAGE AND I WILL
CODE IT."
136 PRINT
137 PRINT "USE A ";CHR$(34) ;".";CHR$(34)
;"TO END CODE."
138 PRINT
140 GET A$:IF A$="" THEN 140
150 LET B=ASC(A$)
160 IF A$=" "THEN PRINT" "; :GOTO 140
170 IF A$="." THEN 220
180 LET D=B+C
185 IF A$<"A" OR AS>"Z" THEN PRINT A$; :G
OTO 140
190 IF D>Z THEN LET D=D-26
200 PRINT CHR$(D);
210 GOTO 140
220 PRINT
230 PRINT "THE CODE IS PLUS?"
240 INPUT E
250 IF E=C THEN PRINT "RIGHT ON"
260 IF E<>C THEN PRINT "WRONG IT IS";C
270 PRINT:PRINT "AGAIN? PRESS Y OR N"
275 GET A$:IF A$="" THEN 275
280 IF A$="Y" THEN 110
290 STOP
Note: In lines 140 and 275, the double quotes""define an empty
string. The symbol rJ represents SHIFT CLEAR/HOME.
"ENIGMA I" 51
''Enigma I''
AIM OF THE GAME
This program converts your computer into a coding typewriter,
something like the German coder of the second world war, which was
called ENIGMA. As you type in a message, it is displayed in coded form.
You terminate your message by typing a period. A space is accepted so
you may use the space key to type a space in your message.
After your message has been typed, you are asked to solve the code.
The letters in the alphabet have simply been shifted to the right by a
constant number of letters. This is the number you are prompted to enter.
Of course it will not be challenging for you because you know what
the original message was! But challenge a friend to solve the code. One
person types in a message and then the other attempts to decode it.
After a little experience you will be a master at decoding secret
messages.
This is a very simple form of coding and would be too easy to crack.
Mathematicians and computer scientists are working on developing codes
that are almost impossible to crack. So much important personal and
financial information is stored in data banks, you can imagine how
important it is to protect that information from unauthorized use.
DOW TO PLAY
The program commences with the prompt
ENTER YOUR MESSAGE AND I WILL CODE IT
USE A . TO END CODE.
Your keyboard will now act like a typewriter. Every key you press will give
an instant response. If you press a letter key, a different letter will appear
on the screen. Other characters will be typed as themselves except for a
period, which will end the input. You will then be asked the question
THE CODE IS PLUS?
You enter your answer, it is checked and a message
RIGHT ON
or
WRONG IT IS 15 (or some such number).
Then you will be invited to play again or to quit.
You might like to try a much more challenging version of "ENIGMA".
In this version, the letters of the alphabet are randomly mixed up! You
52 WORD GAMES
could not find a more difficult code to break. You have to look at patterns
of repeating letters and three letter words and, by trial and error, try to
break the code.
"ENIGMA II" 53
''Enigma II''
100 LET Y=ASC("A")-1
110 PRINT "I:J"
115 PRINT "GENERATING THE CODE"
116 C$="":D$="":REM INITIALIZE
119 FOR I=0 TO 25
121 LET C$=C$+STR$(ASC("A")+1)
123 NEXT I
125 FOR I=1 TO 26
127 LET J=INT(26*RND(0))+1
129 IF MID$(C$1JI1)="*" THEN 127:REM CHE
CKS IF LETTER HAS BEEN ASSIGNED
131 LET C$=LEFT$(C$~J-1)+"*"+RIGHT$(C$ 1 2
7-J) :REM REPLACES LETTER BY *
133 LET B$=B$+CHR$(J+Y) :REM Y DEFINED IN
LINE 1001 THIS CHOOSES A RANDOM LETTER
134 NEXT I
135 PRINT "I:J":PRINT:PRINT "ENTER YOUR ME
SSAGE AND I WILL CODE IT"
136 PRINT:PRINT "USE A ";CHR$(34);".";CH
R$(34);" TO END CODE."
140 GET A$: IF A$="" THEN 140
150 LET B=ASC(A$)-Y:REM B IS A NUMBER FR
OM 1 TO 26
170 IF A$="." THEN 220
175 IF A$<" A" OR A$>"Z" THEN PRINT A$;: G
OTO 9010:REM USE GOTO 140 TO OMIT SOUND
180 LET D$=MID$(B$1BI1) :REM CHOOSES THE
CODED FORM OF INPUT LETTER
190 PRINT D$; :GOTO 9010:REM MAKES SOUND
OF OLD TYPEWRITER (MAY OMIT GOTO 9010)
200 GOTO 140
220 PRINT:PRINT
230 PRINT "PRESS 0 FOR THE CODE 1 FOR A
I
NEW CODE"
235 GET A$:IF A$="" THEN 235
240 E=VAL(A$)
250 IF E<>0 THEN 110
260 PRINT "I:J"
270 FOR I=1 TO 26
280 PRINT CHR$(Y+1) ;"=";MID$(B$1II1)I
54 WORD GAMES
290 NEXT I
295 PRINT:PRINT:PRINT "AGAIN? PRESS Y OR
N"
296 GET A$:IF A$="" THEN 296
297 IF A$="Y" THEN 110
298 STOP
300 PRINT" ";
310 GOTO 140
9000 REM:SOUND OF ANCIENT TYPEWRITER
9010 V=54296:W=54276:A=54277:H=54273:L=5
4272
9020 FOR X=13 TO 10 STEP-1 :POKEV,X:POKEW
,129:POKEA,99:POKE H,40:POKE L,200:NEXT
9030 POKE W,0:POKE A,0:GOTO 140
Note: The symbol C represents SHIFT CLEAR/HOME.
"ENIGMA II" 55
''Enigma II''
HOW TO PLAY
When you run this program it commences with the message
GENERATING THE CODE
After a short period of time, a new message appears
ENTER YOUR MESSAGE AND I WILL CODE IT
You then type in your message. As you touch the keys the message
appears in coded form. You cannot erase mistakes, so type carefully!
Punctuation and other characters appear in their own form, except a
period (.) which terminates your message. You are then prompted with
PRESS 0 FOR THE CODE, 1 FOR A NEW CODE
If you press the key 0, a listing of the code appears, giving the code
letter for each letter in the alphabet, for example
A=T B=R C=Y D=F
E=G F=O G=L H=V
I=J J=C K=N L=B
M=D N=H O=P P=A
O=S R=U S=Q T=M
U=Z V=K W=W X=E
Y=I Z=X
AGAIN? PRESS Y OR N
and you are prompted to play again or to quit.
THE CODE
You may find it inconvenient that the period is used to end the
message. If you have a long message, with many sentences, you may like
to use the period for punctuation. In that case, you should alter line 170
and replace the"." by"#" or something that you prefer.
There are also some small sound effects in lines 9000 to 9030. You
may omit these. Then in lines 175 and 190 you should replace
GOTO 9010
with
GOTO 140
------------------------------------------------------
58 LOGIC AND STRATEGY GAMES
''Invader''
10 PRINT "~":PRINT:PRINT"INSTRUCTIONS? P
RESS Y OR N":PRINT
20 GET AS:IF AS="" THEN 20
30 IF AS<>"Y" THEN 100
40 PRINT "SUBMARINES ARE HIDDEN IN A 9 B
Y 9 SQUARE"
50 PRINT "THERE IS ONE SUBMARINE IN EVER
Y ROW":PRINT
60 PRINT "YOU MUST FIND THE SUBS IN 40 T
RIES"
70 PRINT:INPUT "PRESS RETURN TO START";
100 PRINT "~"
105 LET H=0
106 LET T=0
110 FOR 1=1 TO 9: LET AS(I)="": LET A(I)
=INT(9*RND(0))+1
120 FOR J=1 TO 9: LET AS(I)=AS(I)+"
130 NEXT J,I
140 PRINT "~";TAB(3)
150 FOR 1=1 TO 9: PRINT STRS(I); :NEXT I
160 PRINT
170 FOR 1=1 TO 9:PRINT: PRINT I;A$(1) :NE
XT I
180 IF H=9 THEN 270
185 IF T=40 THEN 300
186 PRINT "ENTER -1 TO QUIT MOVE=";T+1
190 INPUT "ENTER ROW NUMBER";!
200 IF I=-1 THEN 400
210 INPUT "ENTER COLUMN NUMBER";J
215 IF J=-1 THEN 400
220 IF 1<1 OR J<1 OR 1>9 OR J>9 THEN 140
225 LET T=T+1
230 IF MIDS(A$(1) ,2*J,1)="1" THEN 140
235 IF A(I)=J THEN LET H=H+1
240 IF A(I)=J THEN LETS$=" I"
245 IF A(I)<>J THEN LETS$=" *"
250 LET AS(I)=LEFTS(A$(1),2*J-2)+SS+RIGH
TS(A$(1), 18-2*J)
260 GOTO 140
270 PRINT "YOU WIN IN";T;"TRIES"
"INVADER" 59
''Invader''
AIM OF THE GAME
If you think that the Swedish Navy is inept at catching those small
submarines that creep into its territorial waters and seem to escape at
will, then here is your chance to see if you could do any better!
This game sets up a 9 by 9 array of points. The points are displayed
on the screen in 9 rows and 9 columns. Each row is numbered, and each
column is also numbered. There are 9 invading submarines located one to
each row. It is your task to try to locate all the submarines with just 40
moves.
You can try to develop your own search patterns, or you can search
randomly. In any case, you will learn something about the behavior of the
random number function, RND.
HOW TO PLAY
When you run this program, you are confronted with an array of dots
on the screen arranged in nine numbered rows and columns and a
prompt.
2 3 4 5 6 7 8 9
1
2
3
4
5
6
7
8
9
ENTER -1 TO QUIT MOVE
ENTER ROW NUMBER?
ENTER COLUMN NUMBER?
You enter a row number, I, which should be an integer from 1 to 9.
Then you enter a column number, J, also from 1 to 9. Your entries are
checked in line 220. If they are not in the range from 1 to 9 then the
array and prompt are displayed again.
Suppose you enter 5 and then 8. Instantly, the point at the location
row 5 and column 8 on the screen is replaced by * or I. The * indicates
that a submarine was not located at that point, while I indicates that you
have located a submarine.
"INVADER" 61
A count of your attempts is kept by the variable T (for tries). You only
have 40 tries in a game. A count of your successes is kept by the variable
H (for hits). If H < 9 when T = 40, then you have not been able to locate
all the submarines in 40 tries and you have lost the game. The
submarines do not move, so if you repeat the entry of a point, it is
counted as a try, but it is a wasted move.
There are very sophisticated search methods programmed into the
computers onboard the subchasers. These are based upon statistical
theory. However, when all is said and done, if you are lucky, or have a
sixth sense for this sort of thing, you will beat the computer every time.
To quit at any time, enter -1 when prompted to enter the row number
or the column number. The position of the submarines will then be
displayed.
THE MATHEMATICS
This game is meant to give you some experience with probability and
the random number function. You start by setting up a simple search
pattern, say test 1,5 then 2,5 and so on down the fifth column to 9,5.
Then quarter the set of points by testing the 5th row, or another row if the
point 5,5 has already located a submarine. When a submarine is found on
a row, there is no need to test any more points on that row. Odd and even
columns should have the same probability of containing a submarine.
Similarly, columns less than the 5th should be chosen with the same
frequency as columns greater than the 5th. Finally, as you get down to the
last few submarines, you should check those columns that have not
revealed a submarine.
However, after saying all this, in one game anything is possible! You
might try a simple pattern of testing each row sequentially. That is, start
at 1,1 then 1,2 and so on until you find the submarine in that row. Then
you start on the second row. Since there are nine positions on each row,
there is a better than 50% chance of locating the submarine in the first 5
positions of each row. In fact, the probability is %, in other words,
55%%. Overall, this would amount to 45 tries for the 9 rows. What is the
probability of successfully locating all the submarines in 45 tries by this
method?
You could use this game as a research tool to investigate the answer
to this question, but you would need a lot of patience! You would need to
play many times, a hundred would do for a rough estimate. You would
record the number of times this search pattern was successful. You would
need to change line 185 to
For those of you who are like me (a bit lazy), you could change the
program so that the computer does the search for you. The following is a
simple program that does this.
"PROBABILITY'' 63
submarine must be % (they always add up to 1). Since there are nine
rows, we multiply (% + %) by itself 9 times. The terms in this expansion
all add up to 1 and they represent the probabilities of finding 0, 1, 2, ... , 9
submarines respectively. Consequently, the probability of finding all nine
submarines is (%) 9 = .005 (approximately) or Y2 %. So it is a very poor
search pattern!
The numbers that multiply the powers in the expression are called
the binomial coefficients. An easy way to find these numbers is to use
Pascal's triangle.
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1
1 8 28 56 70 56 28 8 1
1 9 36 84 126 126 84 36 9 1
Start and end each row with 1. Add the two numbers above for each entry
in a row. Entries in the nth row are binomial coefficients for (a+b)n-1.
I hope my explanation has not caused you to do anything rash, like
run away to join the Swedish Navy!
66 LOGIC AND STRATEGY GAMES
T$(A$(1),18-2*J)
260 GOTO 140
270 PRINT "YOU WIN IN";T;"TRIES"
280 GOTO 310
300 PRINT "HA, I WIN":FOR T=1 TO 2000:NE
XT:GOTO 400
310 PRINT:PRINT "AGAIN? PRESS Y OR N"
320 GET Z$:1F Z$="" THEN 320
330 IF Z$="Y" THEN 100
340 STOP
400 REM DISPLAYS ALL THE SHIPS
405 PRINT "~":PRINT TAB(3) ;"THE SOLUTION
IS"
410 PRINT TAB(3)
420 FOR 1=1 TO 9:PRINT STR$(1);"NEXT I
430 PRINT
440 FOR 1=1 TO 9:PRINT:PRINT I;
450 FOR J=1 TO 9:P=0:FOR S=1 TO 5:IF A(l
,S)=J THEN PRINT " I";
455 IF A(I,S)=J THEN P=1
460 NEXT S:IF P=0 THEN PRINT" ";
470 NEXT J:PRINT:NEXT I
480 PRINT:INPUT "PRESS RETURN TO GO ON";
490 GOTO 310
500 REM THIS SUBROUTINE SETS UP THE SHIP
S UP-DOWN OR ACROSS
510 PRINT "~":PRINT:PRINT
520 PRINT "SETTING UP THE GAME GO HAVE A
SNACK THIS"
525 PRINT "WILL TAKE A MOMENT"
530 FOR 1=1 TO 9
540 FOR J=1 TO 5
550 LET A(I,J)=0:NEXT J,I:REM INITIALIZE
560 FOR S=2 TO 5
565 LET I=INT((10-S)*RND (0))+1 :REM START
lNG POSITION OF SHIPS
566 LET J=INT(9*RND(0))+1
567 LET D=INT(2*RND(0)) :REM SHIPS GO ACR
OSS IF D=0 AND DOWN IF D=1
570 IF D=0 THEN LET A(1,1)=J
575 IF D=1 THEN LET A(J,1)=1
576 FOR K=2 TO S
578 IF D=0 THEN LET A(I+K-1,1)=J
579 IF D=1 THEN LET A(J,K)=I+K-1
68 LOGIC AND STRATEGY GAMES
''Sea Bunt''
AIM OF THE GAME
This game is similar to "INVADER", but more difficult because there
is less information to guide you. Ships of various lengths from 2 to 5
consecutive positions in the grid are hidden in the 9 by 9 grid of points.
They can be vertical or horizontal. There is no longer any guarantee that
every row will be occupied by a piece of a ship. There are a total of 14 hits
to be made in order to win the game, but you are limited to 40 tries.
BOW TO PLAY
When you run this game a message is displayed
SETTING UP THE GAME GO HAVE A SNACK THIS
WILL TAKE A MOMENT
while the ships are being located randomly in the grid. A grid of points is
then displayed and you are prompted to enter the row number and
column number (I,J) of a grid point. The numbers I,J should be in the
range from 1 to 9. An entry of -1 will quit the game and the location of
the ships will be displayed. A prompt to play again is then given.
THE CODE
This program is much longer than "INVADER" because setting up the
ships is more complicated. The subroutine from lines 500 to 630 does
this. The edge of the ships are located at a safe distance from the
boundaries so they will lie inside the 9 by 9 grid. Then, after the ships
have been randomly located, a count of the occupied points is made. If
this turns out to be less than 14, then two or more ships must have a grid
point in common. This set-up is discarded and another arrangement is
made. For this reason the setting up can take some time.
As a programming exercise, see if you can add to the setting up
routine so that ships can be located diagonally. You would choose four
values for D in line 567. If D=3 then the ship would be located on a
diagonal from left upper to right lower, and for D=4 the ship would be
located in the opposite diagonal direction.
70 LOGIC AND STRATEGY GAMES
''Verif y''
110 LET C=1
120 LET F=INT(10*RN D(0))
130 PRINT "t:'J"
140 PRINT "YOU HAVE 10 GOLF BALLS ONE HA
S A":PRINT
150 PRINT "DIFFERENT WEIGHT FROM THE OTH
ERS. FIND": PRINT
160 PRINT "THE DEFECTIVE BALL BY COMPARI
NG ANY":PRINT
170 PRINT "NUMBER OF BALLS ON A BALANCE
180 PRINT
190 PRINT "ENTER BALL NUMBERS 012 ... 9 IN
A STRING"
195 PRINT:PRINT "FOR EXAMPLE,TO COMPARE
BALLS 0,4,5,7 AND"
196 PRINT "9,ENTER THE STRING '04579'"
200 PRINT:INPUT A$
210 FOR I=1 TO LEN(A$)
215 B$=MID$(A$, I ,1): IF B$<"0" OR B$>"9"
THEN 130:REM CHECKS FOR NUMBERS
220 IF VAL(MID$(A $,I,1))=F THEN 260
230 NEXT I
240 PRINT "EQUAL"
250 GOTO 280
260 PRINT "UNEQUAL"
270 PRINT
280 PRINT "GIVE UP? PRESS Y OR N"
290 GET B$:IF B$="" THEN 290
300 PRINT
310 IF B$="Y" THEN PRINT "YOU HAD";C;"MO
VES. THE BALL WAS?":GOTO 340
320 LET C=C+1
330 IF B$="N" THEN 130
340 INPUT Z
350 IF Z=F THEN PRINT "CORRECT"
360 IF Z<>F THEN PRINT "WRONG. IT WAS";F
370 PRINT "AGAIN? PRESS Y OR N"
380 GET Z$:IF Z$="" THEN 380
"VERIFY" 71
''Verify''
AIM OF THE GAME
This game is similar to "LOOSE CHANGE", but it is much easier. You
should master this game before playing "LOOSE CHANGE".
You have 10 golf balls and a scale. One of the balls is defective as it
does not weigh the same as the others. The balls are numbered 0, 1, 2, ... ,
9. You may select any number of balls to compare their weight. You can
even select an odd number because the computer has a spare good ball
to make up the same number on each side of the scales.
Each time you compare a set of balls you are told whether they are
equal or unequal. The number of moves you take are counted. If you can
find the defective ball in 3 moves or less that is an excellent score. A good
score is 4 or 5 moves. More than 5 moves and you need to practice a few
times. Maybe you would prefer to play with real golf balls on a golf course!
HOW TO PLAY
When we run this program it commences with the message
YOU HAVE 10 GOLF BALLS ONE HAS A
DIFFERENT WEIGHT FROM THE OTHERS.FIND
THE DEFECTIVE BALL BY COMPARING ANY
NUMBER OF BALLS ON A BALANCE.
ENTER BALL NUMBERS 012 ... 9 IN A STRING
FOR EXAMPLE,TO COMPARE BALLS 0,4,5,7 AND
9,ENTER THE STRING '04579'
Suppose we enter the string 12345. In this case we receive the
message
EQUAL
GIVE UP? PRESS Y OR N
We are not ready to quit so we press the key N. The first message is
repeated. This time we might enter the string 6 7 8. Again we received the
message that they are equal. We press N and enter 0. This turned out to
be OK so now we know that 9 is the defective ball. This time we press the
key Y in response to
GIVE UP? PRESS Y OR N
We obtain the message
YOU HAD 3 MOVES. THE BALL WAS?
We enter 9 and obtain the response
"VERIFY" 73
CORRECT
AGAIN? PRESS Y OR N
If you wish to quit, press the key N. Otherwise, press the key Y and a
new game will be generated.
74 LOGIC AND STRATEGY GAMES
''Loose Change''
110 LET C=1
115 LET N=INT(5*RND(0))+1
120 LET F=INT(12*RND(0))+ASC("A")
130 PRINT "l:l"
135 LET B$=""
140 PRINT:PRINT "ONE OF 12 DIMES HAS AD
IFFERENT WEIGHT"
145 PRINT:PRINT "THAN THE REST.FIND THE
ODD DIME BY "
150 PRINT:PRINT "WEIGHING";N;"AGAINST";N
·" ,
155 PRINT:PRINT "WE REPRESENT THE COINS
BY LETTERS A TO L"
160 PRINT "TYPE THE COIN LETTERS A,B,C, .
. . ,L THAT"
165 PRINT:PRINT "YOU WISH TO COMPARE":PR
INT
170 LET 1=0
180 LET W=0
190 GET A$:1F A$="" THEN 190
195 IF A$<"A" OR A$>"L" THEN 190
200 IF A$=CHR$(F) THEN LET W=1
205 FOR J=1 TO I:IF A$=MID$(B$,J,1) THEN
190
206 NEXT J
207 LET B$=B$+A$
210 PRINT A$;
220 LET 1=1+1
230 IF 1<2*N THEN 190
240 PRINT "l:l"
250 IF W=1 THEN PRINT "UNEQUAL"
260 IF W=0 THEN PRINT "EQUAL"
270 PRINT "GIVE UP? PRESS Y OR N"
280 GET A$:1F A$="" THEN 280
290 IF A$="N" THEN 350
300 PRINT:PRINT "YOU HAD";C;"MOVES. THE
COIN WAS?"
310 INPUT B$
320 IF ASC(B$)=F THEN PRINT "CORRECT"
330 IF ASC(BS)<>F THEN PRINT "WRONG! THE
"LOOSE CHANGE" 75
COIN IS ";CHR$(F)
340 GOTO 370
350 LET C=C+1
360 GOTO 130
370 PRINT:PRINT "AGAIN? PRESS Y OR N"
380 GET A$:IF A$="" THEN 380
390 IF A$="Y" THEN 110
400 STOP
Note: In lines 135, 190, 280 and 380, "" are two quotes that
define an empty string. The symbol rJ represents SHIFT CLEAR/HOME.
76 LOGIC AND STRATEGY GAMES
''Loose Change''
AIM OF THE GAME
This is a game of strategy and skill. Someone has been making
counterfeit dimes. "Why bother?", you might ask. That is not the question
we are concerned with. You have 12 dimes, one of which is counterfeit.
An illegal dime does not weigh the same as the genuine article. By
comparing the weight of a chosen number of coins, you must determine
which coin is the counterfeit in the fewest number of moves.
The coins are represented by the letters A,B, ... ,L. You are prompted
to enter letters that represent coins by pressing the appropriate keys. The
number of coins used in the comparison is chosen randomly. This means
that you will have to develop a different strategy each time.
HOW TO PLAY
When you run this program, you are given a message like this
ONE OF 12 DIMES HAS A DIFFERENT WEIGHT
THAN THE REST. FIND THE ODD DIME BY
WEIGHING 3 AGAINST 3
WE REPRESENT THE COINS BY LETTERS A TO L
TYPE THE COIN LETTER A,B,C ... ,L THAT
YOU WISH TO COMPARE
The program makes your keyboard act like a typewriter. The first three
letters you press would be the coins on one side of the scale. The last
three letters represent the coins on the other side. Line 195 ignores any
keys that are not one of the letters A to L and line 205 ignores any
repetitions of the same letters. After you have entered a sufficient
number of letters, 6 in this case, you will be given a message
UNEQUAL (or EQUAL as the case may be)
GIVE UP? PRESS Y OR N
If the fake coin was in your selection, then you would get the
UNEQUAL message. You now press N to continue or Y to stop. Suppose
we entered the letters A,B,C,D,E, and F and were told they were unequal.
We would press N and when the prompt for letters appeared, we might
enter the letters A,B,C,G,H and I. Suppose we now get the message
EQUAL
which means that one of D,E or F is the false coin. We would press N and
enter the letters A,B,C,D,E and G. Suppose these turned out to be
unequal, so then we would try A,B,C,D,G and H. If these turned out to be
"LOOSE CHANGE" 77
will need to include some extra lines between lines 310 and
350. For instance
320 IF ASC(B$)=F THEN PRINT "CORRECT":GO
TO 335
325 PRINT "COIN IS ";CHR$(F) ;" IT IS ";
327 IF H=0 THEN PRINT "LIGHT"
330 IF H=1 THEN PRINT "HEAVY"
333 GOTO 370
335 PRINT "IS IT LIGHT OR HEAVY? ENTER 0
OR 1"
337 INPUT Z
340 IF Z=H THEN PRINT "CORRECT":GOTO 370
345 PRINT "WRONG IT IS "; :GOTO 327
As a boy of 15 I can remember solving the problem in the case of
comparing four coins against four. The teachers at my school were unable
to solve it, so I spent the weekend working on it and was so excited when I
found the solution. My family had to patiently sit through several sessions
while I rehearsed the presentation I intended to give to the teachers in
their coffee room before school started on Monday morning. You can
imagine how I felt when I was told by the faculty that my mathematics
teacher had found the solution and had already bored the entire staff to
tears with his explanations before I had arrived at school! The solution, by
the way, required only three weighings in this case. Can you design such a
scheme?
"NIM I" 79
''Nim I''
100 PRINT "t:l"
110 LET C=INT (10*RND(0))
120 LET 8=C+INT (10*RND(0))
130 LET A=8+INT (10*RND(0))
150 PRINT "t:l"
160 PRINT A;TA8(3);8;TA8(6) ;C
165 PRINT
170 PRINT "YOUR MOVE"
180 PRINT " ENTER THE STACKS IN DECREAS
lNG ORDER"
190 INPUT A,8,C
200 IF A+8+C=1 THEN 400
210 IF 8=0 THEN 420
220 IF C=0 THEN 280
230 IF A=8 THEN LET C=0
240 IF 8=C AND C=1 THEN 340
250 IF 8=C AND C<>1 THEN LET A=0
260 IF A>0 AND C>0 THEN 330
270 GOTO 150
280 IF A>8 THEN 310
290 LET 8=8-1
300 GOTO 150
310 IF 8=1 OR A=1 THEN GOTO 420
315 LET A=8
320 GOTO 150
330 IF A+8+C-6>0 THEN 360
340 LET A=A-1
350 GOTO 150
360 LET S=8+C
370 IF A-6+S>0 AND S>2 AND S<6 THEN LET
A=6-S
380 IF A+8+C=6 THEN 150
390 GOTO 340
400 PRINT "YOU WIN"
410 GOTO 430
420 PRINT "I WIN"
430 PRINT: PRINT "AGAIN? PRESS Y OR N"
440 GET A$:1F A$="" THEN 440
80 LOGIC AND STRATEGY GAMES
''Nim II''
10 PRINT "a":PRINT:PRINT "INSTRUCTIONS?
PRESS Y OR N":PRINT
20 GET A$:1F A$="" THEN 20
30 IF AS<>"Y" THEN 100
40 PRINT "YOU HAVE THREE STACKS OF COUNT
ERS LISTED"
50 PRINT "IN DECREASING ORDER OF MAGNITU
DE.ON YOUR"
60 PRINT "MOVE YOU MAY TAKE COUNTERS FRO
M ONE PILE"
70 PRINT "YOU MAY TAKE ANYTHING FROM ONE
TO ALL OF"
80 PRINT "THE COUNTERS FROM THAT ONE PIL
E"
90 PRINT:INPUT "PRESS RETURN TO START";
100 PRINT "a"
110 LET C=INT(10*RND(0))
120 LET B=C+INT(10*RND(0 ))
130 LET A=B+INT(10*RND(0 ))
150 PRINT "l:l"
160 PRINT A;TAB(3) ;B;TAB(6);C
165 PRINT
170 PRINT "YOUR MOVE":PRINT
180 PRINT " ENTER THE STACKS IN DECREAS
lNG ORDER"
182 INPUT X,Y,Z
183 IF(X+Y+Z)>=(A+B+C ) THEN 150
184 IF (X<>A AND X<>B AND X<>C) AND (Y<>
A AND Y<>B AND Y<>C) THEN 150
186 IF (X<>A AND X<>B AND X<>C) AND (Z<>
A AND Z<>B AND Z<>C) THEN 150
188 IF (Y<>A AND Y<>B AND Y<>C) AND (Z<>
A AND Z<>B AND Z<>C) THEN 150
189 IF X<Y OR X<Z OR Y<Z THEN 150
190 LET A=X
192 LET B=Y
194 LET C=Z
200 IF A+B+C=1 THEN 400
210 IF B=0 THEN 420
220 IF C=0 THEN 280
82 LOGIC AND STRATEGY GAMES
HOW TO PLAY
There are only three stacks of counters. The number of counters in
each stack is chosen randomly and will be from 0 to a maximum of 27.
These numbers are displayed in decreasing order of magnitude.
In this simple version of NIM, you are prompted to enter your move.
You will enter the number of counters left in the stacks after your move,
one at a time, in decreasing order. The program will make dumb moves if
you do not enter the numbers in decreasing order.
Let us suppose that you get the message
12 4 4
YOUR MOVE
ENTER THE STACKS IN DECREASING ORDER
Suppose you enter 4, 4 and then 4, then the response would be
4 4 0
and you would be prompted to enter your move again. Suppose you now
enter 4, 2 and then 0. The response would be
2 2 0
Finally, you would enter 2, 1 and then 0 and the computer would win
because it would remove all the counters from the first stack leaving you
the one counter in the second stack. The response would be:
I WIN
AGAIN? PRESS Y OR N
If you wish to quit you would press the key Nor any key other than Y.
By pressing the key Y you would commence a new game.
84 LOGIC AND STRATEGY GAMES
THE CODE
Since I have not come across a program that plays a perfect game of
"NIM", I decided to try to write one. The listing "NIM Ill" does, I believe,
play a perfect game. However, a law of computing is that there is no such
thing as a perfect program. All I can say is that this program seems to
play a perfect game in the tests conducted at our home.
If you enter this program you will appreciate why I have tried to keep
all the programs in this book as short as possible. When you type in the
listing, I suggest you save your listing from time to time, in order to
protect your work in case of a power failure.
"NIM III" 85
''Nim Ill''
100 PRINT "~":PRINT:PRINT
110 REM: SET UP THE GAME
120 GOSUB 300
130 IF MS="N" THEN 160
140 REM: YOUR MOVE
150 GOSUB 400
160 REM: COMPUTER'S MOVE
170 PRINT "I AM THINKING"
180 GOSUB 500
190 REM: CHECK SPECIAL CASES
200 IF VAL(S$)=1 THEN PRINT:PRINT "YOU W
IN!":GOTO 270
210 GOSUB 600
220 REM: DISPLAY STACKS
230 GOSUB 950
240 IF Z=1 THEN PRINT:PRINT "I WIN, HURR
AH!"
250 IF Z<=1 THEN 270
260 GOTO 140
270 PRINT "AGAIN? PRESS Y OR N"
280 GET ZS:IF Z$="" THEN 280
290 IF ZS="Y" THEN 110
295 STOP
300 PRINT "DO YOU WANT THE FIRST MOVE?P
RESS Y OR N"
305 GET MS:IF M$="" THEN 305
310 PRINT:PRINT "ENTER NUMBER OF STACKS
FROM 3 TO 9"
315 GET SS:IF S$="" THEN 315
320 LET S=VAL(S$)
325 IF S<3 OR S>9 THEN 310
330 PRINT:PRINT "DO YOU WANT TO CHOOSE T
HE NUMBER OF"
335 PRINT "COUNTERS IN THE STACKS?"
340 PRINT:PRINT "PRESS Y OR N"
345 GET SS:IF S$="" THEN 345
350 PRINT "~"
355 FOR 1=1 TO S
360 LET A(I)=INT(15*RND(0 ))+1
365 PRINT "STACK";!;"=";
86 LOGIC AND STRATEGY GAMES
''Nim Ill''
HOW TO PLAY
In this version there are up to 9 stacks of counters. There are many
prompts given so that you can design the game to meet your
requirements for difficulty. A typical run would proceed as follows.
DO YOU WANT THE FIRST MOVE? PRESS Y OR N
If you want the computer to have the first move you would press N. If you
press any other key, you will have the first move. You have to make this
choice before you see the stacks, so don't give the computer the first
move if you want to win! The computer is absolutely ruthless in this game
and plays to win. Only press N if you wish to study how the computer
reacts to a certain given situation.
The next prompt is
ENTER NUMBER OF STACKS FROM 3 TO 9
All you need to do is press a key from 3 to 9. Any other key will not be
accepted and the prompt will be repeated. Suppose you press the key 3.
The next prompt appears.
DO YOU WANT TO CHOOSE THE NUMBER OF
COUNTERS IN THE STACKS?
PRESS Y OR N
If you press the key Y you get a series of prompts like
STACK 1 = ?
You enter a number that can be as large as you like. I would suggest that
you keep it to less than 100 for the sake of keeping the game short. If you
press the key N, the number of counters are chosen for you and are kept
to 15 or less. You could change this by altering line 360.
Suppose you had pressed the key N. Then the situation might be
something like this
STACK 1 8
STACK 2 = 15
STACK 3 = 9
WHICH OF THE STACKS DO YOU WISH TO
ALTER? ENTER 1 TO 3
Suppose you enter 2. Then the next prompt would be
HOW MANY COUNTERS ARE YOU REMOVING?
ENTER 1 TO 15
90 LOGIC AND STRATEGY GAMES
Suppose you enter 10, then the computer would respond with
I AM THINKING
After a short period of time the stacks would be listed again and you
would be prompted to make your move.
Finally, you get a message of victory or defeat and are asked if you
wish to play another game.
This does the trick since 0 is considered even. Similarly, we could have
adjusted 4 by subtracting 4 and adding 3 to give
5 = 101
3 = 11
6 _l_il!
sum 222
As you can see, there is more than one way to make your move.
There are some special situations that occur, such as each stack
having 1 counter, which would have to be handled differently.
The program is fairly complicated to a beginner, so I have used some
block structure and remarks to make it easier for you to follow. All the
action takes place in subroutines. The main program, which calls the
subroutines, is in lines 100 to 295. The subroutine in lines 300 to 390
sets up the game. The subroutine in lines 400 to 450 handles your move.
Converting the stacks to binary and adding up the totals in each column is
done in the subroutine from line 500 to 585. Special cases are handled in
lines 600 to 690, and the computer's move is done in lines 700 to 850.
The display of the stacks is handled in the subroutine from 950 to 980.
You might like to think about this question. How would you modify
the program so that the object of the game is to take the last counter
instead of forcing your opponent to take the last one?
92 LOGIC AND STRATEGY GAMES
''To"Wers of Hanoi''
110 PRINT "~":PRINT "THE NUMBER OF COUNT
ERS IS? ENTER 1 TO 9"
120 LET K=0
130 INPUT N:PRINT "~"
140 IF N<1 OR N>9 THEN 110
150 LET M=0
160 LET A$(1)="ABCDEFGJHI"
170 LET A$ ( 2) ="I I I I I I I I I I"
180 LET A$(3)=A$(2)
190 PRINT "~"
200 LET M=M+1
210 FOR I=1 TO N
220 PRINT MIDS(A$(1),I,1) ;TAB(9) ;MIDS(A$
(2) ,I,1) ;TAB(18) ;MIDS(A$(3) ,I,1)
230 NEXT I
240 IF K=1 THEN 450
250 PRINT:PRINT "ENTER A STRING OF TWO D
IGITS FOR MOVE";M
255 PRINT "FOR EXAMPLE '13' MEANS MOVE T
HE TOPMOST "
260 INPUT "COUNTER FROM STACK ONE TO STA
CK THREE";BS
270 LET C=VAL(MIDS(B$,1,1))
280 LET D=VAL(MIDS(B$,2,1))
290 IF C<1 OR D<1 OR C>3 OR D>3 OR C=D T
HEN 430
300 FOR I=1 TO N
310 IF MIDS(A$(C),I,1)="i'' THEN 420
320 FOR J=N TO 1 STEP -1
330 IF MIDS(AS(D),J,1)<>"1" THEN 380
340 LET AS(D)=LEFTS(AS(D) ,J-1)+MID$(A$(C
) , I, 1 )+RIGHTS(AS(D) ,9-J)
350 IF J=N THEN 390
360 IF MIDS(A$(D),J,1)>MIDS(A$(D),J+1,1)
THEN 430
370 GOTO 390
380 NEXT J
390 LET AS(C)=LEFTS(AS(C), I-1 )+''i"+RIGHT
S(AS(C) ,9-I)
400 IF I=N AND J=1 AND D=3 THEN LET K=1
"TOWERS OF HANOI" 93
''To"Wers of Hanoi''
AIM OF THE GAME
In a monastery, high in the mountains of Tibet, a group of monks
struggle valiantly to save the universe from destruction. Their task,
imposed by a superior being from another universe, is to shift 60
counters of different magnitudes from one stack to another. They are
allowed to form three stacks while doing this. At the beginning, all the
counters are on the first stack, arranged in increasing order. Only one
counter at a time can be moved. The problem is to move all the counters
to the third stack in the least number of moves. There is one vital
restriction. At no time should a greater counter be on top of a lesser one.
One mistake and the universe, as we know it, ends. So the monks toil on,
carefully contemplating each move.
HOW TO PLAY
In this game you get to choose the number of counters (from 1 to 9).
The game commences with a prompt requesting you to enter the number
of counters. You then get to move the counters, which are the letters A, B,
C, ... , initially stacked in increasing alphabetical order from the top down
in the first stack. For example, if you choose 3 counters, the computer
would respond with
A
B
c
ENTER A STRING OF TWO DIGITS FOR MOVE 1
FOR EXAMPLE '13' MEANS MOVE THE TOPMOST
COUNTER FROM STACK ONE TO STACK THREE?
You are invited to enter your move as a two digit number. If you wish to
move the top counter from stack 1 to stack 3, you would input 13. The
computer would respond with the message
B
c A
You might now want to move the counter B from stack 1 to stack 2, so
you would enter 12. The situation would then be displayed as
"TOWERS OF HANOI" 95
c B A
You would then enter 32 followed by 13, 21, 23 and finally 13. The
completion of your task is then signalled by the message
MOVES TO COMPLETE TASK IS 7
THE UNIVERSE IS SAFE, THANKS TO YOU
AGAIN? PRESS Y OR N
If you wish to quit, press the key N. To play another game, press the
key Y. Your moves are checked, if you make a mistake, the universe is
doomed! If you take too many moves, you do not save the universe, but
you do get another chance!
THE MATHEMATICS
I leave you to solve the following mathematical problems. In order to
solve the problem posed by the game in the fewest number of moves, you
will have to move the first counter into the correct stack. For an odd
number of counters, you should move the first counter into which stack?
Once you have this figured out, you will also know which stack to move
the first counter into if you have an even number of counters. Now, what
is the minimum number of moves for N counters? Solve the game for N =
1, 2, 3, ... and see if you can arrive at the general rule.
--------------------------------------------------------------------------------------------------
98 ARITHMETIC GAMES
''Barter''
100 LET COW=INT(151*RND(0) )+20
110 LET Z=INT(COW/19)
120 PRINT "~":PRINT
130 PRINT " CATS ARE WORTH $1"
135 PRINT " HENS ARE WORTH $3"
140 PRINT " DOGS ARE WORTH $5"
145 PRINT "AND PIGS ARE WORTH $10":PRINT
150 PRINT "THERE ARE NO MORE THAN";Z+1 ;"
ANIMALS OF":PRINT
155 PRINT "EACH KIND. HOW MANY OF EACH K
IND WOULD":PRINT
160 PRINT "YOU BARTER FOR A $";COW;" COW
?":PRINT
165 PRINT "ENTER YOUR ANSWER IN A STRING
LIKE 3233":PRINT:INPUT A$
170 PRINT "~"
180 FOR P=-1 TO
190 FOR 0=-1 TO
200 FOR R=-1 TO
210 FOR S=-1 TO 1
220 IF P+3*0+5*R+10*S=COW-Z*19 THEN 240
230 NEXT S,R,Q,P
240 FOR 1=1 TO 4
250 IF VAL(MID$(A$,1,1))>Z+1 THEN 290
260 NEXT I
270 LET A=VAL(MID$(A$,1,1))+3*VAL(MID$(A
$,2, 1) )+5*VAL(MID$(A$,3, 1))
280 IF A+10*VAL(MID$(A$,4,1))=COW THEN P
RINT "YOU ARE CORRECT":GOTO 290
285 PRINT "YOU ARE WRONG!":PRINT
290 PRINT "MY ANSWER IS";P+Z;O+Z;R+Z;S+Z
300 PRINT
310 PRINT "AGAIN? PRESS Y OR N"
330 GET A$:IF A$="" THEN 330
340 IF A$="Y" THEN 100
350 STOP
Note: The symbol ~ represents SHIFT CLEAR/HOME.
"BARTER" 99
''Barter''
AIM OF THE GAME
This is a game that encourages you to sharpen your mental
arithmetic skills. You have a cow worth a given amount. The amount is
chosen randomly. You are seeking a fair exchange for a number of cats,
hens, dogs, and pigs, which are each worth a certain fixed amount. There
is only a limited quantity of each of the cats, hens, dogs, and pigs. You are
asked to determine how many of each you are willing to exchange for your
cow.
HOW TO PLAY
When you run the program a problem is posed like:
CATS ARE WORTH $1
HENS ARE WORTH $3
DOGS ARE WORTH $5
AND PIGS ARE WORTH $10
THERE ARE NO MORE THAN 9 ANIMALS OF
EACH KIND. HOW MANY OF EACH KIND WOULD
YOU BARTER FOR A $54 COW?
ENTER YOUR ANSWER IN A STRING LIKE 3233
Note that your entry should be in a string, so if you decide that you
want 3 cats, 2 hens, 3 dogs and 3 pigs, you would enter 3233. No
individual number will ever exceed 9, so your entry will always contain
only four digits.
The computer checks your answer. If you are right, the computer will
print the message
YOU ARE CORRECT
Then right or wrong, you will get the answer computed by the computer,
MY ANSWER IS 3233
AGAIN? PRESS Y OR N
If you wish to quit, press the key N or any key other than Y. If you
press Y, another problem is given to you.
THE MATHEMATICS
The mathematical solution to this problem is based on the fact that
combinations of the numbers 1 ,3,5 and 10 give you all the numbers from
1 to 19. For instance, 7=10-3, 17=10+5+3-1. Each number is used at
100 ARITHMETIC GAMES
''Base''
110 LET Z=ASC("A")-10
115 PRINT"~"
120 PRINT "ENTER BASE 2 TO 36"
130 INPUT D:IF D< 2 OR 0>36 THEN 115
135 PRINT "t:l"
136 LET S$=""
140 PRINT "BASE IS";D
150 PRINT:PRINT "ENTER ANY NUMBER"
160 PRINT "1 TO 4294967295"
170 INPUT A$
180 LET A=VAL(A$)
182 IF A<1 OR A>4294967295 THEN 135
185 PRINT:PRINT A$;" IN BASE";D;"IS"
190 GOSUB 300
200 PRINT:PRINT
210 PRINT "PRESS 0 FOR NEW BASE"
215 PRINT "1 FOR A NEW NUMBER"
216 PRINT "ANYTHING ELSE TO STOP"
220 GET G$:IF G$="" THEN 220
230 IF G$="0" THEN 115
240 IF G$="1" THEN 135
250 STOP
300 LET I=1
320 LET B=A-D*INT(A/D)
330 LET A=INT(A/D)
335 IF B>9 THEN LET S$=S$+CHR$(Z+B)
336 IF B>9 THEN 350
340 LET S$=S$+STR$(B)
350 LET I=I+1
360 IF A>0 THEN 320
370 FOR J=2*I TO 1 STEP -1
380 LET C$=MID$(S$,J,1)
385 IF C$<>" " THEN PRINT C$;
390 NEXT J
400 RETURN
Note: The symbol ~ represents SHIFT CLEAR/HOME.
102 ARITHMETIC GAMES
''Base''
AIM OF THE GAME
This is a simple program that teaches you how to convert any
decimal number of your choice to its representation in another base of
your choice. Limitations are given in the prompts because:
(a) You will notice that numbers represented in base 2 contain only
two digits, 0 and 1. Generally, a number represented in base N
contains N digits, 0, 1, 2, ... , N-1. We do not have single
characters for representing numbers greater than 9, unlike the
Babalonians of antiquity, who used a base of 60! We use the
letters A, 8, C, ... , Z to represent the numbers 10, 11, 12, ... , 35
respectively. The program could easily be altered so that bases
up to 60 could be used, but then we would have to use the
graphics characters, and it is more difficult to recognize an
increasing order. We would have to establish some order and
commit it to memory. You will find that this limitation will not
prevent you from obtaining the knowledge necessary to convert
a number to its representation in any desired base.
(b) The limitation that the number must be less than 4294967295
is needed because this is the largest integer that your computer
can store accurately. It is 2r32-1, which in base 2 is
represented by thirty two ones, as in 1111111111111111111
1111111111111. The numbers 0 and 1 are represented by
these respective digits in any base. This program does not
convert negative numbers, but it could be done easily. I leave you
to make the necessary changes so that your number lies
between the limits -4294967295 and 4294967295.
If you remove the restriction that numbers must be less than
4294967295 by removing line 182 in the code, then you can
experiment to find out what happens when you enter numbers that
exceed this limit.
The development of computer technology necessitated the study of
representations of numbers in bases other than 10. The number base
usually used by a computer is binary, or base 2. This is the easiest
because there are only two digits needed in the representation of
numbers, 0 to 1. However, base 8 and base 16 are used in many
computers.
The reason that strings were used in the code to store the
representations was that some representations have up to 32 figures in
them, and could not be displayed in number format.
"BASE" 103
HOW TO PLAY
When you run this program the first prompt you are given is
ENTER BASE 2 TO 36
Suppose you enter the number 2. The screen clears and you are
given a new message and prompt
BASE IS 2
ENTER ANY NUMBER
1 TO 4294967295
Suppose you enter the number 15, then below the above message
appears
15 IN BASE 2 IS
1111
This is the representation of 15 in base 2. Then you are given the
prompt
PRESS 0 FOR NEW BASE
1 FOR A NEW NUMBER
ANYTHING ELSE TO STOP
If you enter the number 0, then the screen will clear and the program
returns to the prompt requesting you to enter the base. If you enter the
number 1, then the same base is used and you are prompted to enter any
number. To quit, you just enter any other character, Q for example.
THE MATHEMATICS
The mathematics in this game is repetitive division which is
performed in the subroutine starting at line 300. For instance, in the
example cited above, to express the number 15 in the base 2, use the
following procedure.
2 15 You divide 2 into 15 to get 7 with a remainder of
1. You keep dividing by 2 until you reach 0, the
remainders give you the required representation, in
this case 1111. This binary representation means that:
15 = 1 *(2 t 3) + 1 *(2 t 2) + 1 *(2) + 1
411~13
03
You will have noticed that for a base N, the only digits occurring in
the remainders are N-1, N-2, ... , 1 ,0.
For bases greater than 10, the arithmetic becomes more difficult for
us, but not for the computer. We have to use the letters A, 8, ... to
represent remainders which are greater than 9. For example, in finding
the representation of 119 in the base 12, we proceed in the following
manner.
BOW TO PLAY
When you run this program, the screen clears and a message similar
to this is displayed
BASE IS 11
NUMBER IS 5A2
WHAT IS THE NUMBER IN BASE 10?
The representation 5A2 stands for
5*(11t2) + 10*(11) + 2, which is 5*(121) + 112 = 717. You enter
717 and you will get the message
YOU ARE CORRECT
AGAIN? PRESS Y OR N
If you press the key Y, the screen clears and a new problem is posed.
If you press the key N, or any key other than Y, the program stops.
If you enter an incorrect answer, say you enter 617 in the above
example, then you will receive the message
WRONG, IT IS 717
AGAIN? PRESS Y OR N
THE MATHEMATICS
The mathematics is the reverse of the mathematics in "BASE", so
this time it is repetitive multiplication. Suppose the base is B, and the
representation is 123. The number can be written as a polynomial
1*(Bt2) + 2*(B) + 3 = 1B2 + 2B + 3
"YOUR NUMBER IS UP" 107
''Cryptic''
110 PRINT "~":PRINT:PRINT
120 FOR P=2 TO 9
127 LET S=0
130 PRINT "PRESS THE KEY + OR
140 GET OP$:IF OP$="" THEN 140
145 IF OP$<>"+" AND OP$<>"-" THEN 110
150 LET I=INT(15*RND(0))
155 LET M=10t(9-P)
157 LET L=10t(P-1)
160 LET C=INT(555555555/M*RND(0))
170 LET B=INT(444444444/M*RND(0))
180 IF OP$="+" THEN LET A=C-B
190 IF OP$="-" THEN LET A=C+B
200 IF A<L OR B<L OR C<L THEN 160
205 LET Z=4294967200
206 IF A>Z OR B>Z OR C>Z THEN 160
210 LET B$(1)=STR$(A)
220 LET B$(2)=STR$(B)
230 LET B$(3)=STR$(C)
240 FOR J=1 TO 3
245 LET A$(J)=""
250 FOR K=2 TO P+1
255 LET B=VAL(MID$(B$(J) ,K,1))
260 LET A$(J)=A$(J)+CHR$(B+I+ASC("A"))
270 NEXT K
280 NEXT J
290 PRINT "~":PRINT:PRINT "THE FOLLOWING
EQUATION IS IN CODE":PRINT
300 PRINT A$(1) ;OP$;A$(2) ;"=";A$(3)
320 PRINT:PRINT "ENTER Q TO QUIT"
330 PRINT:PRINT "THE DECODED ANSWER IS?"
340 PRINT:INPUT Z$
345 LET S=S+1
350 IF VAL(Z$)<>C THEN 380
355 PRINT:PRINT "CORRECT"
360 PRINT "NUMBER OF TRIES =";S
361 IF P<9 THEN PRINT "LET ME TRY YOU WI
TH A LONGER ONE"
363 FOR T=1 TO 4000:NEXT T
364 PRINT "1:1"
"CRYPTIC" 109
365 NEXT P
370 PRINT "AGAIN? PRESS Y OR N"
375 GET A$:IF A$="" THEN 375
376 IF A$="Y" THEN 110
377 STOP
380 IF Z$="0" THEN PRINT "THE ANSWER IS"
;C:GOTO 370
385 PRINT "WRONG. ENTER A DIGIT."
390 INPUT W
395 PRINT "t:l"
400 FOR J=1 TO 3
410 FOR K=2 TO P+1
415 LET B=VAL( MID$(8$ (J) ,K,1))
416 LET J$=CHR$ (W+ASC ("0"))
420 IF B=W THEN LET A$(J)=L EFT$(A $(J) ,K-
2)+J$+R IGHT$(A $(J),P+1 -K)
430 NEXT K
440 NEXT J
460 GOTO 290
Note: The symbol t:l represents SHIFT CLEAR/HOME.
110 ARITHMETIC GAMES
''Cryp tic''
AIM OF THE GAME
In this program you have the choice of problems in addition or
subtraction. You are presented with an equation in code, where the digits
in the numbers are represented by letters. For instance, the equation
123+234=357
might be displayed as
ABC+BCD=CEG
The game is to work out the answer 35 7 in the fewest number of
moves. You are given clues as you proceed, and based upon these and
your deductive reasoning powers, you work out the answer.
You are given two letter numbers to start with, and each time you
solve a problem, the next problem involves numbers with one extra digit,
up to a maximum of 9 digits.
HOW TO PLAY
When you run this program, you are prompted by the message
PRESS THE KEY + OR -
Say you press +, the screen clears and you are presented with an
equation involving two digit numbers, for instance
THE FOLLOWING EQUATION IS IN CODE
LS+NP=PN
THE DECODED ANSWER IS?
Suppose you enter 53, since L and S appear in the problem, L can
not be 0, so it might be 1 and S would then be 8. Of course L could be 2
and then S would be 9, in which case, the correct answer would be 64. If
you are wrong, the message
WRONG.ENTER A DIGIT
appears on the screen. You might enter the digit 6. The screen would
clear and you would be presented with the equation
LS+N6=6N
THE DECODED ANSWER IS?
Now you know that the answer is 64, so you would enter 64. Then
you would be given the message
CORRECT
NUMBER OF TRIES=2
"CRYPT IC" 111
THE COD E
You should be able to deduce the answer in 2 moves at most. If you
would like to increase the difficulty , then you would need to replace the
digits by letters in an arbitrar y fashion, rather than in a sequence as this
program does. I leave you to make the necessary changes.
Since the arithme tic with 9 digit numbers is not always exact, lines
205 and 206 guard against any of the numbers exceeding the largest
integer 429496 7295 which can be stored exactly inside the computer.
You could attempt to change the code, so that every number is treated as
a string. You would have to introduce subroutines to accomplish the
arithme tic on the strings, but then the limitation of 9 digit numbers could
be removed.
112 ARITHMETIC GAMES
So the rule is
HOW TO PLAY
When you run this program the screen clears and you are given a
message like this (although the + symbol might be -, *Or /)
RIGHT ON
AGAIN? PRESS Y OR N
If you press the key Y you get another problem. Pressing any other
key stops the game. If you enter an incorrect result, say -12,10 in the
above example, you are given the message
WRONG IT IS -12,4
AGAIN? PRESS Y OR N
116 ARITHMETIC GAMES
THE CODE
You should note that when an example is given for division, roundoff
in the machine may cause a perfectly good answer to be rejected as
wrong. For instance, a fraction like h and .14285 7143 would not be
considered to be the same. For this reason, the answers E and F are
entered as strings. The lines 370 and 395 scan the entries for a I. If it is
there, the fraction is correctly evaluated. This allows you to enter your
answer like 7'7 in precisely that fashion. If your entry is a number, it is
treated as such.
"JUGS" 117
''.Jugs''
10 PRINT "~":PRINT:PRINT "INSTRUCTIONS?
PRESS Y OR N":PRINT
20 GET A$:IF A$="" THEN 20
30 IF A<>"Y" THEN 100
40 PRINT "YOU HAVE TO MEASURE A PRECISE
AMOUNT OF "
50 PRINT "MILK USING THREE JUGS OF DIFFE
RING SIZES"
60 PRINT "BY ADDING AND REMOVING AMOUNTS
OF MILK
70 PRINT "WITH THE THREE JUGS"
80 PRINT:INPUT "PRESS RETURN TO START";
100 PRINT "~"
110 LET A=INT(10*RND(0))
120 IF A-2*INT(A/2)=0 THEN 110
130 LET B=A+2*(INT(10*RN D(0))+1)
140 LET C=A+2*(INT(10*RN D(0))+1)
150 IF C=B THEN 140
160 LET D=INT(20*RND(0))
170 IF D=A OR D=B OR D=C OR D=0 THEN 110
180 PRINT:PRINT "YOUR THREE JUGS HOLD"
190 PRINT:PRINT STR$(A) ;",";STRS(B);" AN
D";STR$(C);" PINTS."
200 PRINT:PRINT "HOW WOULD YOU GET";D;"P
INTS?"
210 PRINT:PRINT "ENTER YOUR SOLUTION IN
THE FORM -2,1,2"
215 PRINT "WHICH MEANS YOU WOULD ADD THE
SECOND JUG"
216 PRINT "PLUS TWICE THE THIRD, AND SUB
TRACT TWICE"
218 PRINT "THE FIRST JUG"
220 PRINT:INPUT "ENTER R,S,T";R,S,T
230 FOR L=1 TO 9
240 FOR I=-L TO L
250 FOR J=-L TO L
260 FOR K=-L TO L
270 IF I*A+J*B+K*C=D THEN 290
280 NEXT K,J,I,L
290 IF A*R+B*S+C*T=D THEN PRINT:PRINT "R
118 ARITHMETIC GAMES
''Jags''
AIM OF THE GAME
This is a painless way of practicing your arithmetic. You have three
measuring jugs which hold different amounts of milk. By adding and
subtracting the contents of the jugs, you have to get a precise quantity
which is requested by a customer, who has a large empty container. There
is usually more than one correct answer, so do not be surprised if your
answer is different from the one given by the computer.
HOW TO PLAY
When you run the program, the screen clears and you are given a
message like
YOUR THREE JUGS HOLD
5,11, AND 25 PINTS.
HOW WOULD YOU GET 2 PINTS?
ENTER YOUR SOLUTION IN THE FORM -2,1,2
WHICH MEANS YOU WOULD ADD THE SECOND JUG
PLUS TWICE THE THIRD, AND SUBTRACT TWICE
THE FIRST JUG
ENTER R,S,T?
One solution is -4 of the 5 pint jug, +2 of the 11 pint jug. So you
would enter the numbers -4, then 2, and then 0. The computer checks
your answer, and also works out an answer for itself. Then you would get
the message
RIGHT ON
MY ANSWER IS 1,2 AND -1
AGAIN? PRESS Y OR N
If your answer was not correct, the computer gives you the answer it
computed. To obtain another problem, just press the key Y. If you wish to
quit, just press the key N.
THE CODE
The lines 230 to 280 find a solution. The surprising thing in these
problems is that at least one solution is usually found in the range -3 to 3
for the measuring jugs. You might like to increase the possible size of the
measuring jugs by changing lines 110 to 140, in which 10*RND(0) could
be altered to 20*RND(0) or something else. You will notice that in these
lines I have made the quantities A,B and C, which are the volumes of the
120 ARITHMETIC GAMES
three jugs, to be always odd. The final quantity D can be either odd or
even. Can you tell why I had to impose this restriction? It is an odd
thought!
122 GEOMETRY GAMES
''Detonation''
100 REM:SET UP BOMB COORDINATES
1 10 FOR I= 1 TO 3
120 LET X(I)=INT(100*RND(0))
130 IF X(I)=0 THEN 120
140 LET A(I)=0
150 NEXT I
160 LET C=0
170 PRINT "l:l"
180 LET D=0
190 FOR I=1 TO 3
200 LET D=D+ABS(X(I)-A(I))t2
210 NEXT I
220 LET D=INT(SQR(D))
230 IF D=0 THEN 400
240 IF C=20 THEN 420
250 PRINT "YOU ARE AT";STR$(A(1));",";ST
R$ (A( 2));","; STR$ (A( 3)): PRINT
255 PRINT "IN A LARGE HOTEL WHICH HAS 10
00000 ROOMS"
260 PRINT "A TIME BOMB IS SET AT A DISTA
NCE";D:PRINT
261 PRINT "YOU HAVE";20-C;"MOVES TILL IT
GOES OFF":PRINT
265 PRINT "PRESS S TO STOP RETURN TO CON
TINUE"
270 GET A$:IF A$="" THEN 270
280 PRINT:PRINT "ENTER 0 TO 99"
290 INPUT "ENTER COORDINATE A";A(1)
300 INPUT "ENTER COORDINATE B";A(2)
310 INPUT "ENTER COORDINATE C";A(3)
320 LET C=C+1
330 GOTO 170
400 PRINT "WELL DONE! YOU LOCATED THE BO
MB IN ONLY";C;"MOVES."
405 IF C<4 THEN PRINT "YOU MUST BE A GEN
IUS."
406 IF C>3 AND C<9 THEN PRINT"YOU ARE VE
RY CLEVER."
407 IF C>8 THEN PRINT "YOU NEED PRACTICE
"DETONATION" 123
''Detonation''
AIM OF THE GAME
A bomb has been planted somewhere in a large building that has one
million rooms in it. Your job is to locate the bomb before it goes off! To
give you some assistance, your computer tells you how far away you are
from the bomb. You move to another room and the new distance from the
bomb lets you know if you are getting any warmer or colder (which in our
house around Easter egg-time means getting nearer or further away).
Each move is counted and you have a limit of only 20 moves until the
bomb explodes. This is a challenging game and the suspense builds as
you approach the moment of DETONATION. Fortunately no one is hurt if
you fail to find the bomb in time, so you can have another go if you fail,
and another, and ...
HOW TO PLAY
You start at the room with coordinates 0,0,0. Each room is
designated by a set of three coordinates, 0 to 99, 0 to 99, 0 to 99. With
each turn you are given the distance, D, from your present position and
the bomb and are prompted to enter new coordinates. The distance is
measured by the Euclidean rule, or 2-norm, which is
D=SQR((A-X) 2 + (B-Y) 2 + (C-Z) 2 )
Actually, you are given an integer, INT(D). The coordinates X, Y and Z are
the bomb coordinates, while A, B and C are the coordinates for your
present position. When you enter new coordinates, the values of A, B and
C are altered to the new values that you enter.
A typical game goes as follows. The first message is something like
this
YOU ARE AT 0,0,0
IN A LARGE HOTEL WHICH HAS 1000000 ROOMS
A TIME BOMB IS SET AT A DISTANCE 44
YOU HAVE 20 MOVES TILL IT GOES OFF
PRESS S TO STOP RETURN TO CONTINUE
When you press a key other than S, you are prompted to enter your
coordinates A, B and Cone after the other. These are your guesses for the
bomb coordinates X, Y and Z respectively. Suppose you enter 44, then 0
and then 0. The screen clears and a new message appears
YOU ARE AT 44,0,0
IN A LARGE HOTEL WHICH HAS 1000000 ROOMS
''DETONATION'' 125
THE MATHEMATICS
Mathematically, the solution is given by the point of intersection of
three spheres inside the cubic building centered, as an example, at
(0,0,0), (99,0,0) and (0,99,0).
That is, you must solve
x2 + y2 + z2 = Di
(X - 99) 2 + Y2 + Z2 = D~
X2 + (Y - 99) 2 + Z2 = D~
If you do this you are guaranteed to find the bomb in 3 moves! This is an
example of the use of a branch of mathematics called analytic geometry
which is a very useful mathematical technique. If you study calculus at a
university, you will also study analytic geometry.
To solve this system of second degree equations, we subtract the
first equation from the second to obtain
(X - 99) 2 - X2 = D~ - Di
Expanding the first part we get
X2 - 198X + (99) 2 - X2 = D~ - Di
Cancelling the X2 , we get by subtracting (99) 2 from both sides
-198X = - (99) 2 + D~ - Di
Since the distances D1 and D2 are given to you, all of the quantities
on the right hand side are known, so we can find X by dividing by -198.
We do the same with the third equation. We subtract the first
equation from the third equation to get
(Y - 99) 2 - Y2 = D~ - Di
From which we obtain Y.
126 GEOMETRY GAMES
Finally, Z is found from the first equation, now that we know what X
and Y are. Thus
z2 = Of - x2 - y2
We take the positive square root for Z.
Note: All of this is perfectly correct in theory, provided the distances
0 1 , 0 2 and 0 3 are known exactly. However, in this game the distances are
rounded off to integers. It usually makes no difference. However, I want to
warn you that if, after all this analytic geometry and algebra, you are still
distance 1 from the bomb, you will have to finish the problem "by guess
and by golly".
If you fail to find the bomb in 20 moves, the bomb explodes with a
SLAM and the coordinates where the bomb was located are displayed.
There is nothing sacred about the points (99,0,0) and so on that I
used in my solution. You will find that the arithmetic is easier to do if you
use the points (50,0,0), (0,50,0) and (0,50,0). I leave you to work out
the details.
THE CODE
Line 420 creates flashing lights by changing the screen colors. While
lines 9000 to 9999 make the funeral music. You could delete these lines
and line 425 to shorten the listing. You would need to have a line 420
because it is referred to in lines 240 and 280. You could use
420 GOTO 422
Note the difference in the output in lines 250 and 426. When you
use STR$(A(l)) a blank appears only on the left of the number A(l), to
allow the possibility of a negative sign.
"QUEST" 127
''Quest''
10 PRINT "~":PRINT:PRINT:PRINT" NEED
INSTRUCTIONS? PRESS Y OR N"
20 GET AS:IF AS="" THEN 20
30 IF AS<>"Y" THEN 100
40 PRINT:PRINT "YOU ARE AT THE CENTER OF
AN ISLAND WHICH"
50 PRINT "IS A SQUARE WITH SIDES FROM -9
9 TO 99
60 PRINT "TREASURE IS BURIED ON THE ISLA
NO AND YOU"
70 PRINT "WANT TO FIND IT IN 11 MOVES OR
LESS
80 INPUT "PRESS RETURN TO GO ON";
100 PRINT "~"
110 LET C=0
120 LET A=0
130 LET B=0
140 LET T=INT{199*RND{0))-99
150 LET R=INT{199*RND{0))-99
160 IF T=A AND R=B THEN 120
170 LET D=ABS{A-T)+ABS{B-R)
180 IF 0=0 THEN 250
190 PRINT "~":PRINT:PRINT
200 PRINT "YOUR PRESENT POSITION IS";STR
$ {A) ; " , " ; S TR$ { B ) : PRINT
205 PRINT "THE TREASURE IS BURIED";D;"PA
CES AWAY":PRINT
206 PRINT "ENTER -111 TO OUIT":PRINT
210 INPUT "ENTER COORDINATE A";A
215 IF A=-111 THEN 285
220 INPUT "ENTER COORDINATE B";B
225 IF B=-111 THEN 285
230 LET C=C+1
240 GOTO 170
250 PRINT:PRINT "YOU FOUND IT IN ONLY ";
C; "MOVES"
260 IF C<4 THEN PRINT "YOU'RE A GENIUS":
GOTO 290
270 IF C>=4 AND C<12 THEN PRINT "YOU ARE
VERY SMART":GOTO 290
128 GEOMETRY GAMES
''Quest''
AIM OF THE GAME
You start at the center (0,0) of a square island with sides of length
199. Somewhere in the square is buried the pirates' treasure. The
coordinates of the treasure are T and R which will be integers from -99 to
99. The difference between your coordinates (A,B) and the location of the
treasure (T,R) is given to you at each turn and you are asked to supply
new coordinates. You enter your new coordinates A and B one at a time.
They can be any integers. The distance is different from the Euclidean
distance used in "DETONATION". The distance from (A,B) to (T,R) is
defined as
D = ABS(A-T) + ABS(B-R)
This measure of distance is referred to as the 1-norm.
A count of your moves is kept and if you are too slow, the pirates beat
you to the treasure. This program is fun to run and it is not difficult to
beat the pi rates.
HOW TO PLAY
A typical run would proceed in this fashion. You are given the
message
YOUR PRESENT POSITION IS 0,0
THE TREASURE IS BURIED 131 PACES AWAY
ENTER -111 TO QUIT
ENTER COORDINATE A?
Suppose you enter 99 and then 0 to test the extreme of one
coordinate. In this trial run we received the following message
YOUR PRESENT POSITION IS 99,0
THE TREASURE IS BURIED 185 PACES AWAY
So we were on the right track, but we overshot the mark. This means
that we improved for a distance X, then we worsened by that same
amount, and worsened another 27 units after that. So 99 = 2X + 27
which gives X = 36. So the first coordinate is 36. Let us try 36, followed
by 95 (which adds up to 131). The message we got was
YOU FOUND IT IN ONLY 2 MOVES
YOU'RE A GENIUS
AGAIN? PRESS Y OR N
130 GEOMETRY GAMES
If you wish to play again, press the key Y. By pressing any other key,
you will quit the game.
If the explanation for my move was not very helpful, you should read
the next section where a different approach is suggested. Even if you have
no trouble locating the treasure, you might find something of value in the
mathematical description.
The two squares usually intersect at two points. (Why not no points?)
However, in rare instances they may touch at only one point, or they may
coincide along a portion of a common boundary so that there are an
infinite number of points in common. In the latter case, you have to shift
to a new location and waste a turn.
"QUEST" 131
You are lucky if there is only one point in common because that is the
solution. For the usual case of two points in common you only have to
check one point. You have a 50% chance of being right. In any case, you
are guaranteed to find the solution in three attempts (unless you were
unlucky and had to waste a turn).
So far I have only given you a geometrical interpretation of the
solution to this problem. How do you go about producing numbers?
I suggest that instead of using equations as we have done in other
cases, this time you should use graph paper. Locate an origin in the
middle of your paper, draw a horizontal line and a vertical line through
your origin. These are your coordinate axes. Now locate the point (A,B) on
your map (it is the origin to start with) and draw the square which is a
distance 0 from the point (A,B). You do this by locating the corners at
(A+O,B), (A-0,8), (A,B+O) and (A,B-0). Now join the corners by straight
lines using a ruler and you will have drawn the square. The treasure lies
somewhere on this square. Now shift your coordinates to another point
and draw the second square with the value of 0 given to you by the
computer. From your graph, estimate the coordinates of the points of
intersection of the squares and try entering them. After some trial and
error, you will become more proficient at drawing graphs and you will
easily be able to find the treasure before the pirates get to it because they
do not have any graph paper!
THE CODE
Lines before 100 may be left out since they only give instructions.
Note the use of INPUT messages. Line 80 contains only a device for
stopping the execution of the program while the screen message is being
read.
132 GEOMETRY GAMES
''Tre k''
10 PRINT "a":PRINT :PRINT"IN STRUCTIO NS? P
RESS Y OR N":PRINT
20 GET A$:IF A$="" THEN 20
30 IF AS<>"Y" THEN 100
40 PRINT "YOUR SPACESHIP IS LOST IN A CU
BIC BLOCK"
50 PRINT "OF SPACE. HOME BASE IS SOMEWHE
RE IN THE"
60 PRINT "CUBE. YOU HAVE TO FIND THE COO
RDINATES"
70 PRINT "(H,O,M) OF HOME BASE, THEY ARE
NUMBERS"
80 PRINT "BETWEEN 0 AND 99.":PRIN T
90 INPUT "PRESS RETURN TO START"; :REM WA
ITS WHILE SCREEN MESSAGE IS READ
100 PRINT "1:.1"
110 LET E=0
120 LET A=0
130 LET B=0
140 LET C=0
150 LET H=INT(100 *RND(0))
160 LET O=INT(100 *RND(0))
170 LET M=INT(10 0*RND(0))
180 LET D=ABS(A-H)+ABS(B-O)+ABS(C-M) :REM
COMPUTES DISTANCE FROM HOME BASE
190 IF D=0 THEN 300
200 PRINT "a"
210 PRINT "YOUR SPACESHIP IS AT"
220 PRINT A;",";B;" ,";C:PRIN T
230 PRINT "THE DIFFERENCE BETWEEN YOUR C
OORDINATES":PRINT
240 PRINT "AND HOME BASE IS";D:PRI NT
250 PRINT "ENTER COORDINATES FOR A JUMP
TO HOME":PRINT
255 PRINT "BASE.ENTER -1 TO OUIT.":PR INT
260 INPUT "ENTER YOUR ESTIMATE OF H";A
262 IF A=-1 THEN 380
264 INPUT "ENTER YOUR ESTIMATE OF O";B
265 IF B=-1 THEN 380
266 INPUT "ENTER YOUR ESTIMATE OF M";C
"TREK" 133
''Trek''
AIM OF THE GAME
This game is similar to the earlier game of "QUEST". You are the
captain of a spaceship lost in space. You only know the absolute
difference between your coordinates, (A,B,C) and HOME BASE, (H,O,M).
The values of H,O and M can be anything from 0 to 99. You are asked to
supply new coordinates each time you jump through space. The aim is to
get to HOME BASE in the fewest number of turns. If you can do it in three
moves or less you are a GENIUS. Good luck!
HOW TO PLAY
A typical run would proceed in this fashion. We are given the
message
YOUR SPACESHIP IS AT
0,0,0
THE DIFFERENCE BETWEEN YOUR COORDINATES
AND HOME BASE IS 52
ENTER COORDINATES FOR A JUMP TO HOME
BASE, ENTER -1 TO QUIT.
ENTER YOUR ESTIMATE OF H?
Suppose we enter 52, then enter 0 and 0 in response to the prompts
to enter 0 and M. The message is repeated, only this time the distance
turned out to be 76! Evidently we overshot by 24. If we reduce the jump
by 24 and enter 28,0,0 then the difference would remain at 52. This
means that the correct jump is to 14,0,0 and the difference from home
base would be 38. We could now try the warp coordinates 14, then 38,
and then 0. After this move, the distance turned out to be 20. We
continue to try different values in the second coordinate until we are
satisfied that we can not get any closer to home by changes in the second
coordinate. Then we change the last coordinate.
There is a very neat mathematical way of solving this problem in 3
moves. If you are interested, you should read the next section.
THE MATHEMATICS
The mathematical problem behind this game is to find the point of
intersection of three planes. A plane in three-dimensional space is a linear
equation in three variables, such as
2X + 3Y- 4Z = 5
--------------------
You always start at the point (0,0,0), and the ship is located at an
unknown point (H,O,M). All the coordinates are non-negative, so the first
distance 01, supplied to you tells you that the sum of the coordinates H,O
and M is 0 1• We write this as
H + 0 + M = 01
If you shift to a point say (99,0,0), then the new distance 0 2 supplied
to you by the computer tells you that the sum of the difference 99-H,O
and M is 0 2 . We write this as
(99-H) + 0 + M = 02
Similarly a shift to (0,99,0) gives you a third distance 03 and a third
linear equation
H + (99-0) + M = 0 3
The solution of these three equations guarantees that you will get
home in three moves, but don't tell you friends how you did it! If you are
having trouble solving these equations, read on.
You should subtract the first equation from the second one to get
(99-H) - H = 0 2 - 0 1
so that 99 - 2H = 0 2 - 01 . This means that
2H = 99 + 0 1 - 0 2 or H = (99+0 1 - 0 2)/2
and H should be an integer, otherwise you have made a mistake in your
arithmetic.
In exactly the same way, when you subtact the first equation from the
third, you will get
0 = (99 + 0 1 - 0 3 )/2
Then, from the first equation, you can find M = D1 - H - 0.
If you would like to practice Gauss Elimination on the matrix
representing the three equations, then you start with the matrix
1 1 1 01
-1 1 1 02-99
1 -1 1 03-99
and add the first row to the second row to get
1 1 1 01
0 2 2 0 1+0 2-99
1 -1 1 Or99
then subtract the first row from the third row to get
1 1 1 01
0 2 2 01+02-99
0 -2 0 Or0 1-99
"TREK" 137
Now you add the second row to the third row to get
1 1 1 01
0 2 2 0 1 +0 2 -99
0 0 2 0 2 +0r198
This is the equivalent system of equations that you can solve by back
substitution. The last equation states that
2M = 02 + 03 - 198 or M = (0 2 + 0 3 )/2 - 99
The second to the last equation gives you
0 = (0 1 + 0 2-99)/2 - M
The first equation gives
H = 01 - 0- M
In this case, the formal process of Gauss Elimination takes longer
than the elimination process described earlier. The point is, Gauss
Elimination can be programmed easily. It does not pay attention to any
particular short cuts that a system of equations may have, but plods a
well defined path to the ultimate goal.
THE CODE
As usual in these listings, lines 10 to 90 give information, while lines
9000 to 9999 create the sound and screen effects. You could ignore
these lines and also delete line 2 7 5 for a much shorter program.
138 GEOMETRY GAMES
''U-Boat''
10 PRINT "~":PRINT:PRINT "INSTRUCTIONS?
PRESS Y OR N":PRINT
20 GET A$:IF A$="" THEN 20
30 IF AS<>"Y" THEN 100
40 PRINT "YOU ARE IN CONTROL OF A SUBCHA
SER. YOUR"
50 PRINT "SONAR GIVES THE RANGE AND BEAR
lNG OF A"
60 PRINT "SUBMARINE. THE SUB IS LOCATED
SOMEWHERE"
70 PRINT "IN A SQUARE -99 TO 99, AND IS
AT A DEPTH"
80 PRINT "OF 0 TO 99. YOUR TASK IS TO FI
ND THE SUB"
90 INPUT "PRESS RETURN TO START";
100 PRINT "~"
110 LET S=INT(199*RND(0))-99:REM SET UP
SUBMARINE COORDINATES
120 LET U=INT(199*RND(0))-99
130 LET B=INT(99*RND(0))
140 LET C=0
150 LET X=0
160 LET Y=0
170 LET Z=0
180 GOSUB 400
190 IF S-X=0 THEN LET A=SGN(U-Y)*90:REM
SUB IS DIRECTLY NORTH OR SOUTH
200 IF S-X<>0 THEN LET A=INT(ATN((U-Y)/(
S-X))*180/rr) :REM SUB BEARING
210 IF S-X<0 THEN LET A=A+180
220 PRINT "SUBMARINE BEARING:";A;"DEGREE
S"
230 PRINT:PRINT "RANGE:";R;"METERS"
235 PRINT:PRINT "YOUR PRESENT POSITION I
S ";X;",";Y
240 PRINT:PRINT "ENTER COORDINATES X,Y A
ND Z FOR THE SUB. USE -111 TO QUIT."
250 PRINT:INPUT "ENTER COORDINATE X";X
252 IF X=-111 THEN 330
254 INPUT "ENTER COORDINATE Y";Y
"U-BOAT" 139
''U-Boat''
AIM OF THE GAME
You are in control of a subchaser. The detection devices, called
SONAR, on your ship provide you with the range and bearing of the U-
boat. Your job is to track down the U-boat in less than 20 moves. This is
similar to the game "DETONATION", however, you have to use both the
Cartesian coordinate system, (X,Y,Z) and the cylindrical polar coordinate
system (R,A,Z).
The U-BOAT is located at the Cartesian coordinates (S,U,B). The S
and U values are the coordinates in the X (or East) direction and theY (or
North) direction and are integers randomly chosen from -99 to 99. The
value of B is the depth, and is an integer from 0 to 98. Evidently, this U-
BOAT cannot fly!
Your coordinates initially are set to be X=0, Y=0 and Z=0. Based
upon the range and bearing of the submarine, you enter your guess at the
coordinates S, U and B. Your subchaser moves to the new position X=S,
Y=U and Z=0. The coordinate Z remains 0 since your subchaser remains
on the surface, at least until you are hit by a torpedo, which does happen
if you are too slow in finding the submarine!
A new range and bearing are given to you, and again you are
prompted to enter your guess at the coordinates S,U and B. The chase
continues until you locate the submarine, or run out of moves.
DOW TO PLAY
A typical run of this program commences with a message like this.
SUBMARINE BEARING: 82 DEGREES
RANGE: 105.569882 METERS
YOUR PRESENT POSITION IS 0,0
ENTER COORDINATES X,Y AND Z FOR THE SUB.
USE -111 TO QUIT.
ENTER COORDINATE X?
You enter your guess of X, then Y and finally the depth Z. If you are not
successful in locating the submarine, your subchaser will now be located
at (X,Y,0). The coordinate Z is set to zero, since your subchaser remains
on the surface, at least until you are hit by a torpedo (which does happen
if you are too slow in finding the submarine!)
The distance is measured in the Euclidean or 2-norm, so the
mathematical way of solving this game is similar to the method described
"U-BOAT" 141
S2 + U2 + B 2 Rf
where R1 , R2 and R3 are the initial range and the ranges at (50,0,0) and
(0,50,0) respectively. Solve these equations and you are guaranteed to
locate the submarine in 3 moves!
THE CODE
The range or distance in the program is the Euclidean distance
worked out in the subroutine at line 400,
This is not the distance a crow flies, unless the submarine happens to
be on the surface. Rather, it is the distance a fish swims, to coin a phrase!
The value of R is not an integer, and this makes the arithmetic more
difficult. If you would prefer an integer, put INT in front of the SQR in line
400, but that could be misleading as you found in "DETONATION".
The tricky piece of mathematics in this program, is in the calculation
of the BEARING or direction of the submarine. Here, I use the usual polar
coordinates, based on the East and North coordinates of your ship and
the submarine.
142 GEOMETRY GAMES
N (S, U)
U-Y
(X,Y) S-X E
The submarine is located at (S,U) and you are at (X,Y). The difference
in the East direction is S-X while the difference in the North direction is U-
Y. The BEARING, or angle measured in degrees in a counter clockwise
direction from the East direction is A=ATN((U-Y)/(S-X)) .
Since the submarine could be in any of the four quadrants relative to
your position, this angle can be positive or negative. In lines 190 to 210, I
take care of this as well as the case when S=X, where the submarine is
either directly north or south of you.
"WARP" 143
''Warp ''
10 PRINT "O":PRINT:PR INT"INSTRUC TION? P
RESS Y OR N":PRINT
20 GET AS:IF A$="" THEN 20
30 IF AS<>"Y" THEN 100
40 PRINT " YOUR SHUTTLE IS LOST IN A TIM
E WARP."
50 PRINT "YOUR INSTRUMENTS ONLY GIVE YOU
THE NET"
60 PRINT "ABSOLUTE DIFFERENCE IN YOUR CO
ORDINATES"
70 PRINT "AND THE COORDINATES OF YOUR MO
THER SHIP"
80 PRINT "YOU HAVE FUEL FOR ONLY 20 MOVE
S TO FIND"
90 PRINT "THE COORDINATES X,Y,Z AND T 0
F YOUR"
95 PRINT "MOTHER SHIP.":PRINT :INPUT "PRE
SS RETURN TO START"; :REM MAKES A PAUSE
100 PRINT "0"
110 LET E=20
120 LET A=0
130 LET B=0
140 LET C=0
145 LET F=0
150 LET H=INT(100*R ND(0)) :REM SETS UP SH
IPS COORDINATES
160 LET O=INT(100*R ND(0))
170 LET M=INT(100*R ND(0))
175 LET G=INT(100*R ND(0))
180 LET D=ABS(A-H)+ABS(B-O)+ABS(C-M)+ABS
(F-G) :REM COMPUTES DISTANCE
190 IF D=0 THEN 300
200 PRINT "0"
210 PRINT "YOUR SHUTTLE IS LOST IN A TI
ME WARP":PRINT
220 PRINT "DISTANCE FROM SHIP IS";D;"GAL
ACTIC UNITS":PRINT
230 PRINT "YOUR COORDINATES ARE";STRS(A )
·" "·STRS(B)·" "·STRS(C)·" "·F·PRINT
I I I I I I I I I 0
VES"
250 PRINT:PRINT "ENTER COORDINATES 0 TO
99 OF YOUR SHIP"
255 PRINT:PRINT "ENTER -1 TO OUIT":PRINT
260 INPUT "ENTER COORDINATE X";A
261 IF A=-1 THEN 400
262 INPUT "ENTER COORDINATE Y";B
263 IF B=-1 THEN 400
264 INPUT "ENTER COORDINATE Z";C
265 IF C=-1 THEN 400
266 INPUT "ENTER COORDINATE T";F
267 IF F=-1 THEN 400
270 LET E=E-1
275 IF E=0 THEN 400
276 PRINT "~":GOSUB 9000:REM FLASHES COL
ORS FOR SPACE JUMP AND PLAYS MUSIC
280 GOTO 180
300 PRINT "Q":PRINT "SUCCESS! YOU ARE HO
ME IN";20-E;"MOVES":PRINT
310 IF E>16 THEN PRINT "YOU SHOULD BE A
STOCK BROKER!"
320 IF E<17 AND E>8 THEN PRINT "YOU ARE
VERY CLEVER"
330 IF E<9 THEN PRINT "GOOD TRY"
340 PRINT:PRINT "AGAIN? PRESS Y OR N"
350 GET AS:IF A$="" THEN 350
360 IF AS="Y" THEN 100
370 STOP
400 PRINT "Q"
405 PRINT "TOO BAD YOU RAN OUT OF FUEL"
410 PRINT "THE SHIP WAS AT";H;O;M;G
420 GOTO 330
9000 REM:SOUND AND COLORS
9010 FOR L=54272 TO 54296:POKE L,0:NEXT:
POKE 54296,15
9020 FOR I=1 TO 3:V=54269+7*I:POKE V+1,1
90:POKE V+2,250:NEXT I
9030 RESTORE:REM RESETS DATA
9035 FOR I=1 TO 3:POKE 54269+7*I,33:NEXT
I
9040 FOR I=1 TO 3:READ H(I) ,L(I) :NEXT I:
READ D
9050 IF D=-1 THEN 9090
9060 FOR I=1 TO 3:V=54266+7*I:POKE V,H(I
"WARP" 145
''Warp''
AIM OF THE GAME
This is the most difficult of all the hide and seek type of games in this
book. You are separated from your spaceship. You are in a shuttle lost in
a time warp! Your instruments can only give you the total difference in
your coordinates and those of the ship. There are four such coordinates,
three spatial coordinates and one for time. You are prompted to enter
new coordinates each move and you are given your new distance from the
spaceship. You enter the coordinates one after the other. You only have
sufficient fuel for 20 moves, after that you are doomed to float about in
space forever!
HOW TO PLAY
When you run this program you are given a message like this
YOUR SHUTTLE IS LOST IN A TIME WARP
DISTANCE FROM SHIP IS 73 GALACTIC UNITS
YOUR COORDINATES ARE 0,0,0,0
YOU HAVE FUEL FOR ONLY 20 MOVES
ENTER COORDINATES 0 TO 99 OF YOUR SHIP
ENTER -1 TO QUIT
ENTER COORDINATE X?
You enter your guess at the coordinates, one coordinate after the
other. The new message will give you a new distance from your ship. If you
try to solve this game by "guess and by golly", you will have a very
difficult time solving it in the 20 moves allowed. But then again, you might
be lucky.
THE MATHEMATICS
Using analytic geometry, the solution is found in four moves by
finding the point of intersection of four hyperplanes. A hyperplane in the
space with coordinates X, Y, Z, T is represented by a linear equation such
as
2X + 3Y + 5Z + T = 24
I suggest that you go back to the game called "TREK" and master
that game first. The mathematical explanation there will help you. This
game is very similar and you should be able to find four linear equations
in the four unknowns. Thus you are guaranteed a solution in four moves.
If you do better than that, you should become a stock broker!
CHAP TER VI
148 ALGEBRA GAMES
''Monkey Puzzle''
100 FOR A=3 TO 8
105 PRINT"t:l"
110 LET B=INT((A-1)*RND(0))+1
120 PRINT A;"MEN COLLECT A PILE OF COCON
UTS THEY"
130 PRINT "INTEND TO SHARE.WHILE THE OTH
ERS SLEEP,"
140 PRINT "EACH MAN IN TURN WAKES UP AND
DIVIDES"
150 PRINT "THE PILE EVENLY AND HE HAS";B
;"LEFT OVER"
155 PRINT "WHICH HE HANDS OVER TO A MONK
EY,THEN HE"
160 PRINT "HIDES HIS SHARE. NEXT MORNING
THEY"
170 PRINT "SHARE THE REST OF THE COCONUT
S,GIVING";STRS(B)
175 PRINT "TO THE MONKEY."
176 PRINT
180 PRINT "HOW MANY DID THEY HAVE AT THE
START?"
190 INPUT C:IF C=0 THEN 190
200 LET B=INT(At(A+1)-B*(A-1))
210 LET Z=INT(C/B)-C/B
220 IF Z<>0 THEN 270
230 PRINT "RIGHT.NOW TRY ONE MORE"
240 FOR T=1 TO 2000:NEXT T
250 NEXT A
270 FOR I=1 TO A+1
280 LET S=INT(C/A)
290 PRINT" DIVISION ";I;" IS ";S;" MON
KEY GETS ";C-A*S
300 LET C=(A-1)*S
310 NEXT I
320 PRINT "YOUR ANSWER IS WRONG"
330 PRINT "IT SHOULD BE";B
340 PRINT:INPUT "PRESS RETURN TO GO ON";
350 PRINT:PRINT AGAIN? PRESS Y OR N"
360 GET AS:IF A$="" THEN 360
"MONKEY PUZZLE" 149
''Monkey Puzzle''
AIM OF THE GAME
This is a very tricky puzzle. Your ability to work out the answers will
not necessarily depend upon the amount of mathematics you have
studied. I ran into this problem at a party of university mathematics
professors and their wives. None of the wives had any mathematics
training beyond high school, and yet the most elegant solution to this
puzzle was given by one of the wives, in a matter of a few minutes.
A pile of coconuts is divided up among a group of men in a strange
fashion. First of all, one man divides the pile into equal piles and finds out
that he has some left over, which he gives to a nearby monkey. (That is
where the monkey comes into the story.) The man takes his share away,
and heaps the remaining piles back into one pile. Each of the men, in turn,
do the same thing. There is always the same number of extra coconuts,
which are given to the monkey. Finally, they divide the pile once more, and
again there is the same remainder given to the monkey.
The question you have to answer is: How many coconuts were there
at the start?
The program provides you with all the information necessary to solve
the problem. You start with three men. When you get a correct answer,
you progress to more difficult problems.
HOW TO PLAY
When you run the program, a problem is posed. All the information
needed to solve the problem is given to you. For instance, the first
problem given to you might look like this
3 MEN COLLECT A PILE OF COCONUTS THEY
INTEND TO SHARE.WHILE THE OTHERS SLEEP,
EACH MAN IN TURN WAKES UP AND DIVIDES
THE PILE EVENLY AND HE HAS 1 LEFT OVER
WHICH HE HANDS OVER TO A MONKEY,THEN HE
HIDES HIS SHARE. NEXT MORNING THEY
SHARE THE REST OF THE COCONUTS,GIVING
TO THE MONKEY.
HOW MANY DID THEY HAVE AT THE START?
When you have worked out your answer, you enter it. Suppose you
enter the number 121. The computer will work out the division at each
stage, and display the remainder to be given to the monkey. This way you
"MONKEY PUZZLE" 151
can check the accuracy of your arithmetic. In this case, the computer will
display the following:
DIVISION 1 IS 40 MONKEY GETS 1
DIVISION 2 IS 26 MONKEY GETS 2
DIVISION 3 IS 17 MONKEY GETS 1
DIVISION 4 IS 11 MONKEY GETS 1
YOUR ANSWER IS WRONG.
IT SHOULD BE 79
PRESS RETURN TO GO ON
AGAIN? PRESS Y OR N
You can see that the result of the second division is wrong. You also
learn what the correct answer should be. You press Y and the program
continues by asking you another problem. There are only two problems
involving 3 men. In one, the monkey gets 1 coconut, in the other he gets
2. If you get the same problem, you will enter 79 and the computer will
respond with:
RIGHT.NOW TRY ONE MORE
After a short pause, a new problem will be posed involving 4 men. Each
time you get a correct answer, the new problem involves one more man.
The maximum number of men is 8 because the numbers become too
large for your computer with any more men!
THE MATHEMATICS
The solution is provided by the formula in line 200. Since any
multiple of this solution is also a solution, line 210 checks whether your
answer is a multiple of the solution. You may wonder how I arrived at the
solution. Well I used an old mathematical trick of "borrowing" some
hypothetical coconuts at the start to make the arithmetic work out
exactly, without any remainder, and then the "borrowed" coconuts are
returned after the final division is made.
To understand this process, we use a little algebra. We let X be the
number of coconuts to start with. In the illustrative example given in HOW
TO PLAY, after X has been divided by 3, there is one left over, then X+2
will be exactly divisible by 3 with none left over. So we borrow 2 coconuts
to make the stack X+2. Now, after X+2 has been divided into 3 equal
piles, each pile contains one more coconut than it should. So the first
man, let's call him A, gives his extra one to the monkey. Then he hides his
correct amount. The remaining two stacks will still contain 2 more
coconuts than they are supposed to. This means that the next division by
3 will also work out with none remaining. This time the second man, call
him B, gives his extra one to the monkey. And so on. Every time the
division by 3 works out with no remainder, each man hides his correct
152 ALGEBRA GAMES
amount by giving one to the monkey, so the monkey gets the correct
amount. In the last division, each man has an extra coconut. One man
gives his to the monkey, the other two return one each of the borrowed
coconuts. All the conditions have been satisfied. So X+2 is divisible by 3 a
total of 4 times. So X+2 =constant *81. The constant can be 1,2, .... Say
it is 1, then X+2=81 or X=79.
This solution is fairly neat, but becomes more difficult to generalize
to the case of any number of men M and a remainder of R= 1 or 2 or ...
M-1. The following is the solution given by the wife of a mathematical
colleague of mine.
Consider the number -2. If you divide -2 by 3, you get three equal
shares of -1, and + 1 left over! Give the + 1 to the monkey, take one share
of -1 away, and you are left with two shares of -1 for a total of -2. Thus,
the number -2 is never changed by the process. Any number that is
divisible by 3 a total of 4 times may be added to this -2. So we add
k*3 4 =k*81 where k=1,2, .... For k=1, we have
X = -2 + 81 = 79
This process is more easily generalized. The monkey gets the positive
remainder, while the men each get a share which is the negative of the
monkey's share.
Suppose we have M men, and the monkey gets a remainder of R.
Then the men each get an equal share of -R. This means the "magic"
number is
M*(- R) + R = - R*(M- 1)
In the case worked out above, M=3, R= 1 so the "magic" number is
-1 *(3-1) = -2.
Now we add a multiple of MM+l to the "magic" number to get the
required formula. The case when the multiple is 1 gives
X = Mt(M+1) - R*(M-1)
"OBSCURE AGES" 153
''Obscure Ages''
100 PRINT "1:1"
110 LET P=INT(10*RND(0) )+5
120 LET J=P+INT(20*RND(0))
130 LET R=J+INT(20*RND(0))
140 PRINT "RON IS";R-J;"YEARS OLDER THA
N JIM":PRINT
150 PRINT "RON IS";R-P;"YEARS OLDER THA
N PAT":PRINT
160 PRINT "THEIR COMBINED AGE IS";P+J+R:
PRINT
170 PRINT "WHAT ARE THEIR AGES?":PRINT
175 INPUT "ENTER PAT'S AGE";A
180 INPUT "ENTER JIM'S AGE";B
185 INPUT "ENTER RON'S AGE";C:PRINT
190 IF P=A AND J=B AND R=C THEN 220
200 PRINT "WRONG IT IS ";P;",";J;",";R
210 GOTO 230
220 PRINT "RIGHT ON"
230 FOR T=1 TO 2000:NEXT T
240 PRINT:PRINT "AGAIN? PRESS Y OR N"
250 GET AS:IF A$="" THEN 250
260 IF AS="Y" THEN 100
270 STOP
Note: The symbol 1:1 represents SHIFT CLEAR/HOME.
154 ALGEBRA GAMES
''Obscure Ages''
AIM OF THE GAME
You are given information about the ages of RON, JIM and PAT. From
this information you are asked to deduce their ages. This game is meant
to give you practice at solving a linear system of algebraic equations.
When you have worked out their ages, you enter their ages one after the
other in the order requested by the prompting message on the screen.
HOW TO PLAY
A typical run starts with the following message
RON IS 6 YEARS OLDER THAN JIM
RON IS 24 YEARS OLDER THAN PAT
THEIR COMBINED AGE IS 72
WHAT ARE THEIR AGES?
ENTER PAT'S AGE?
ENTER JIM'S AGE?
ENTER RON'S AGE?
When you have worked out their ages, you enter them in the order
requested, one after the other. Suppose you enter 10, 28 and 34
respectively. You are given the message
RIGHT ON
AGAIN? PRESS Y OR N
If you enter an incorrect answer, then you receive the message
WRONG IT IS 10,28,34
AGAIN? PRESS Y OR N
If you wish to have another go, press the key Y, otherwise press N.
THE MATHEMATICS
The mathematics behind this game is called linear algebra. In this
case, you have to solve three linear equations simultaneously. Let us
suppose that the ages of PAT, JIM and RON are represented by the letters
P, J and R respectively. Then in the game presented in HOW TO PLAY, we
conclude from the given data that
R- J = 6
R- P = 24
P + J + R = 72
"OBSCURE AGES" 155
THE MATHEMATICS
Once again you must solve linear equations. We let P, J and R be the
respective ages of PAT, JIM and RON. Then from the information given
we have
P - 8 = 6(R - 8) or P = 6R- 40
J - 8 = 5(R - 8) or J = 5R - 32
and finally,
P + J + R = 84
If we substitute for P and J in the final equation, which is like
subtracting the first two equations from the third equation, we get
12R - 72 = 84 or 12R = 156 or R = 13
Substituting in the first two equations gives P = 6(13) - 40 or P =
38, and J = 5(13) - 32 = 33.
When you have mastered this game, you should try yourself on
"MUCH MORE OBSCURE AGES". Try to solve the game without referring
to the section on the mathematics.
158 ALGEBRA GAMES
''Much More
Obscure Ages''
100 PRINT "t."J"
110 LET P=INT(25*RND(0))+10
120 LET O=INT(5*RND(0))+2
130 LET Z=INT(5*RND(0))+2
135 IF O=Z THEN 120
140 LET J=O*P
143 LET R=(Z+0)/2
145 IF INT(R)-R<0 THEN 120
147 LET R=R*P
148 IF P>99 OR J>99 OR R>99 THEN 110
150 PRINT "WHEN RON WAS AS OLD AS JIM IS
NOW, HE":PRINT
155 PRINT "WAS";Q;"TIMES AS OLD AS PAT I
S NOW.":PRINT
156 PRINT "WHEN JIM IS AS OLD AS RON IS
NOW, RON":PRINT
157 PRINT "WILL BE";Z;"TIMES AS OLD ASP
AT IS NOW.":PRINT
160 PRINT "THEIR COMBINED AGE IS";P+J+R;
".":PRINT
170 PRINT "WHAT ARE THEIR AGES?":PRINT
175 INPUT "ENTER PAT'S AGE";A
180 INPUT "ENTER JIM'S AGE";B
185 INPUT "ENTER RON'S AGE";C:PRINT
190 IF A=P AND B=J AND C=R THEN 220
200 PRINT "WRONG IT IS ";P;",";J;",";R
210 GOTO 230
220 PRINT "VERY CLEVER OF YOU"
230 FOR T=1 TO 2000:NEXT T
240 PRINT:PRINT "AGAIN? PRESS Y OR N"
250 GET AS:IF AS="" THEN 250
260 IF AS="Y" THEN 100
270 STOP
Note: The symbol t."J represents SHIFT CLEAR/HOME.
"MUCH MORE OBSCURE AGES" 159
''Much More
Obscure Ages''
HOW TO PLAY
This game is similar to the previous two games, but more difficult as
the name implies. A typical problem looks like this
WHEN RON WAS AS OLD AS JIM IS NOW, HE
WAS 2 TIMES AS OLD AS PAT IS NOW.
WHEN JIM IS AS OLD AS RON IS NOW, RON
WILL BE 6 TIMES AS OLD AS PAT IS NOW.
THEIR COMBINED AGE IS 154.
WHAT ARE THEIR AGES?
ENTER PAT'S AGE?
ENTER JIM'S AGE?
ENTER RON'S AGE?
As before, you enter the ages in the requested order. If you are
wrong, the correct answer is given to you. In any case, a prompt is given
to continue with another problem or to quit.
THE MATHEMATICS
As before, we let the ages be represented by P,J and R respectively.
From the information given in the problem, we have to introduce another
unknown, say D, which is the difference in the ages of RON and JIM. Then
we have
J = R- D = 2P
R + D = 6P
P + J + R = 154
If we add the first two equations, the D is eliminated to give 2R=8P
or R=4P. We also have J=2P from the first equation, so substituting
these into the third equation gives
7P= 154 or P=22
So J=44 and R=88.
THE CODE
The essential difficulty in preparing the code was to define the
correct quantities. P and the multipliers are defined. J was automatically
defined from these quantities. Now came the tricky part. I tried defining a
160 ALGEBRA GAMES
difference D, but the arithmetic would not work out. The solution was to
define R, but only if the sum of the multipliers are even!
Now I leave you with the question, why was this restriction imposed?
The multipliers are Q and Z, and R is defined to be
(Q + Z)
R *P , (see lines 143 to 147)
2
GENERAL MATHEMATICS
BACKGROUND
The three games involving OBSCURE AGES all involved systems of
linear equations, which we solved by manipulating the equations to obtain
a simpler equation involving just one unknown. We then substituted the
value of this unknown back into other equations.
One of the major uses of computers is to solve very large systems of
linear equations that may contain thousands of equations. The equations
are stored in matrix form and many methods have been designed to solve
these large systems economically and accurately. Numerous books have
been written about matrix algebra and linear systems and a lot of
research is being done right now on these problems. By the term matrix,
we mean an array. For example the linear equations X + Y + Z = 4 , 2X-
Y = 3, 2Y - Z = 5 can be represented by the array
1 1 1 4
2 -1 0 3
0 2 -1 5
Here we drop the X, Y, Z and = . The columns keep track of which symbol
belongs to which number. Now in order to solve this system, we first
reduce it to an equivalent system that has the same solution, but is
simpler to solve. We subtract twice the numbers in the first row from the
corresponding numbers in the second row so that the number 2 in the
first column becomes 0. Thus the equivalent system is
1 1 1 4
0 -3 -2 -5
0 2 -1 5
We now add the numbers in the third row to the corresponding numbers
in the second row to get the equivalent system
1 1 1 4
0 -1 -3 0
0 2 -1 5
Now we add twice the numbers in the second row to the corresponding
numbers in the third row which reduces the number 2 in the third row,
second column to 0. The equivalent system is
"MUCH MORE OBSCURE AGES" 161
1 1 1 4
0 -1 -3 0
0 0 -7 5
Now we solve this system which is called a row reduced system, where the
matrix of coefficients is said to be triangular. The method of solution is
called back-substitution. We start with the third row, that stands for
- 7Z = 5
The solution is easy. It is Z = -o/1. The second to the last row stands for
- Y - 3Z = 0 or Y = - 3Z = 1o/7
Finally, the first row stands for
X+Y+Z=4
but now we know what Y and Z are, so
X= 4 - Y - Z = 4 - 1 o/1 + o/1 = 1 o/1
This process is called Gauss Elimination.
162 ALGEBRA GAMES
HOW TO PLAY
Prompts provide you with all the instructions necessary. A typical run
would look like this
PRODUCT A*B*C=336
SUM A*B+A*C+B*C=-50
AND SUM A+B+C=-7
THE VALUES OF A,B AND C ARE FROM -9 TO 9
AND A<=B<=C. WHAT ARE A,B AND C?
ENTER THE VALUE OF A?
Suppose you work out that A = -8, B = -6 and C = 7 then you would
enter these numbers one by one. After each entry you are given a
message. After you enter A you are told
A IS RIGHT
After you enter B, the message
B IS RIGHT
appears, and after you enter C you get the message
RIGHT ON
AGAIN? PRESS Y OR N
If you want another problem, press the Y key. If you wish to quit, just
press any other key.
If you enter an incorrect entry then the message WRONG appears
and you are prompted to quit or to try the same problem again.
THE MATHEMATICS
The arithmetic way of solving this problem is to find all the factors of
the product. In the example given, this would be:
336 = 2*2*2*2*3*7
164 ALGEBRA GAMES
or
A3 + 7 A 2 - 50A - 336 = 0
which is a single cubic (degree three) equation in A. You will notice that
the coefficients in this equation are the numbers (except for signs) that
appeared in the statement of the problem. The reason for this is that the
cubic equation for A contains all the information about the three
unknowns. The three roots of this equation will represent the three values
of A, B and C.
If we consider the three factors (X-A), (X-B) and (X-C) and multiply
them together we get
If we substitute the values given for the sums and products we get
X3 + 7X 2 - 50X - 336
The roots of this polynomial are the values A, B, and C that we seek.
By trial and error we first substitute X = 1, -1, 2, -2 and so on until
we get X= -6. We find that the expression is zero. This means that one of
the roots is -6, and one of the factors is X+6. We now divide the factor
(X+6) into X3 + 7X 2 - 50X- 336 using the process of synthetic division
described in "YOUR NUMBER IS UP".
"PRODUCT AND SUMS" 165
1 7 -50 -336
THE CODE
For a more challenging game of product and sums, you might like to
alter the definitions of A, 8 and C in lines 110 to 130 to allow larger
numbers.
Note: To find out more about roots and root finding, check into the
programs "FIXED-POINT" and "BRACKET" in Chapter VII of this book.
166 ALGEBRA GAMES
''Rally''
100 PRINT "t:l"
110 LET R=INT(9*RND(0))+5
120 LET C=R+INT(15*RND(0))+5
125 IF C<R THEN 110
130 LET I=INT(80*RND(0))+20
140 LET J=INT(80*RND(0))+20
150 LET T=I+J
160 LET D=R*I+C*J
165 IF D>1000 THEN 110:REM LIMIT TOTAL D
!STANCE TO 1000 MILES
170 PRINT "YOU CAN RUN AT A SPEED OF";R;
"M.P.H.":PRINT
180 PRINT "AND YOU CAN CYCLE AT";C;"M.P.
H. HOW LONG":PRINT
190 PRINT "WOULD YOU RUN AND HOW LONG WO
ULD YOU":PRINT
195 PRINT "CYCLE SO AS TO COVER ";D;"MIL
ES IN";T:PRINT
196 PRINT "HOURS EXACTLY?":PRINT
200 INPUT "ENTER RUN TIME";A:INPUT "ENTE
R CYCLE TIME";B;PRINT
210 IF A=I AND B=J THEN PRINT "RIGHT"
220 IF A<>l OR B<>J THEN PRINT "WRONG. I
T IS";I;",";J
230 PRINT "AGAIN? PRESS Y OR N"
240 GET AS:IF A$="" THEN 240
250 IF A$="Y" THEN 100
260 STOP
Note: The symbol t:1 represents SHIFT CLEAR/HOME.
"RALLY" 167
''Rally''
AIM OF THE GAME
This is a simple game where you are asked to cover a given distance
in an exact time. You may run or ride a bicycle. The speeds for both
modes of travel are given to you.
This is a quick and easy game to play and is designed to shape up
your ability to do mental arithmetic. It involves the solution of linear
equations, only this time you have two equations in two unknowns.
DOW TO PLAY
A hypothetical run could go like this. You are presented with a
problem
YOU CAN RUN AT A SPEED OF 1 M.P.H.
AND YOU CAN CYCLE AT 3 M.P.H. HOW LONG
WOULD YOU RUN AND HOW LONG WOULD YOU
CYCLE SO AS TO COVER 264 MILES IN 118
HOURS EXACTLY?
ENTER RUN TIME?
ENTER CYCLE TIME?
Suppose you work out the run time to be 45 hours and the cycle time
to be 73 hours. You would enter 45 and then 73. You are correct, and the
computer responds with the message
RIGHT
AGAIN? PRESS Y OR N
If you want to try another problem, press the Y key. Press the N key
to quit.
If you enter a wrong answer, you will be given the correct answer and
prompted to continue or to quit.
THE MATHEMATICS
If we let the run time be R and the cycle time be C, then from the
information given in the sample problem, we can write down two
equations. They are
(l)R+C 118
(2) R + 3C = 264
168 ALGEBRA GAMES
''Fixed-Point''
100 DEF FNG(X)=-(P*X*X+O*X+R)/(X*X)
110 PRINT"~": LET I=0
120 PRINT "DEFINE FUNCTION X=G(X) IN LIN
E 100"
130 PRINT:PRINT "NUMBER OF SIGNIFICANT D
IGITS? ENTER 1-8"
140 INPUT S
150 LET S=.5*10t(1-S)
160 PRINT:PRINT "ENTER P,O,R"
170 INPUT P,O,R
180 PRINT:PRINT "ENTER INITIAL VALUE OF
THE ROOT"
190 INPUT X1
200 PRINT "~":PRINT "ITERATION ROOT DIG
ITS"
210 LET I=I+1
220 LET X2=FNG(X1)
230 LET A=ABS((X2-X1)/X2)
240 PRINT I;TAB(5) ;X2;TAB(14) ;INT(1-LOG(
2 *A) I LOG ( 10) )
250 LET T=ABS((FNG(X2)-FNG(X1))/(X2-X1))
260 IF T>=1 THEN PRINT "NOT CONVERGING"
270 IF A<=S THEN PRINT "CONVERGED.ANOTHE
R ROOT? PRESS Y OR N":GOTO 300
280 LET X1=X2
290 GOTO 210
300 GET Z$:IF Z$="" THEN 300
310 IF Z$="Y" THEN LET I=0:PRINT "~":GOT
0 180
320 STOP
Note: The symbol ~ represents SHIFT CLEAR/HOME.
''FIXED-POINT '' 171
HOW TO PLAY
Messages and prompts give you all the instructions that you need.
However, you will need to have some values of P, Q and R. I suggest you
use the values given in the program "PRODUCTS AND SUMS". In which
case P = 7, Q =-50 and R = -336. In every case the R in this program is
-(PRODUCT), Q = (SUM OF PRODUCTS), and P = -(SUM). You can
make up your own values, like 3,4 and 5, or 6, 7 and 8 etc. Then
experiment with different starting values.
''FIXED-P OINT'' 173
''Bracket''
100 DEF FNF(X)=X*X*X+P*X*X+O*X+R
110 PRINT "a":LET I=0
120 PRINT "DEFINE FUNCTION F(X)=0 IN LIN
E 100"
130 PRINT:PRINT "NUMBER OF SIGNIFICANT D
IGITS? ENTER 1-8"
140 INPUT S
150 LET S=.5*10t(1-S)
160 PRINT:PRINT "ENTER P,O,R"
170 INPUT P,Q,R
180 PRINT:PRINT "ENTER X1,X2 THAT BRACKE
T THE ROOT"
190 INPUT X1,X2
200 LET X3=(X1-X2)/2
205 PRINT:PRINT "ENTER 1 FOR BISECTION M
ETHOD":PRINT
206 PRINT "OR 2 FOR REGULAR FALSI":INPUT
M
210 PRINT "ITERATION ROOT DIGITS"
220 LET F1=FNF(X1)
230 LET F2=FNF(X2)
235 IF SGN(F1)=SGN(F2) THEN PRINT "ROOT
NOT BRACKETED":PRINT
236 IF SGN(F1)=SGN(F2) THEN PRINT "CONT
INUE? PRESS Y OR N":GOTO 340
240 LET I=I+1
250 LET X4=(X1+X2)/2:IF M=2 THEN LET X4=
(F1*X2-F2*X1)/(F1-F2)
260 LET F3=FNF(X4)
270 IF SGN(F3)=SGN(F1) THEN LET X1=X4
280 IF SGN(F3)=SGN(F2) THEN LET X2=X4
285 IF X4=0 THEN LET X4=. 1E-10
290 LET A=ABS((X3-X4)/X4)
300 PRINT I;TAB(5) ;X4;TAB(14) ;INT(1-LOG(
2 *A) I LOG ( 10) )
310 LET X3=X4
320 IF A<=S THEN PRINT "CONVERGED.ANOTHE
R ROOT? PRESS Y OR N":GOTO 340
330 GOTO 220
340 GET ZS:IF Z$="" THEN 340
"BRAC KET" 175
''Bracket ''
If you have not tried "FIXED-POINT", please do so before running this
program.
HOW TO PLAY
Messages and prompts give you all the instructions that you need. As
in the program "FIXED-POINT", you will need to enter values of P, Q and
R that define a cubic X3 + PX 2 + QX + R for which you wish to find a zero.
An essential difference in this program is that you must enter two initial
values. These two values must bracket the zero. This means one must be
less than the zero, while the other must be more. If you have no idea
where the zero is, you might try -100,000 and 100,000. This is crude,
but it works.
This program provides you with a menu of two different methods.
They are very similar in nature. The difference will be explained in the
mathematics section. Simply experiment by choosing either of the two
methods.
If you fail to choose initial values that bracket a root, then a message
will be given to you prompting for new initial values.
THE MATHEMATICS
There are two methods used in this program. The first method is
called the method of BISECTION. It is a very simple idea, and it always
works, provided the function is continuous. Polynomials are always
continuous, so it will always find the real zeros of polynomials.
We wish to find a zero of the function F(X) that lies between two
values X1 and X2 . We simply evaluate the function at both X 1 and X2 , say
F1 = F(X 1 ) and F2 = F(X 2 ). Now we choose the mid-point of the interval
[X 1 , X2 ]. That is, let
X3 = (X 1 + X2 )/2 . We find F3 = F(X 3 ).
If the sign of F3 is the same as the sign of F1 , we replace X 1 by X3 ,
otherwise we replace x2 by x3.
x3
_ _ _ ._X_ __
By doing this we have halved the width of the interval that contains
the required zero. After 10 such halvings, we will have reduced the
interval by a factor of 1024!
"BRACKET" 177
The reason for the subtractions is that F1 and F2 have opposite signs,
so in effect, we will now be adding quantities with the same sign, (unless
the values of X have different signs, in which case X3 should be nearer 0).
Note: This is a very powerful program for finding the zeros of any
kind of function, not just polynomials. It has only one fault. That is, it can
only find real roots. If roots are complex, then there are other methods
designed for just that purpose.
PROBL EMS
Here are some problems for you to experiment with.
1. Find a root of X3-X-1=0 in the interval [1,2] to an accuracy of 5
significant figures.
2. Find a root of X-2-x=0 in the interval [0, 1] to an accuracy of 5
significant figures.
3. Solve the equations
(a) 3X = 2-3x+X 2
(b) X = cosX
(c) 2sinX = X near X = 1. 7
(d) X = tan X near X = 100 (difficult to bracket the root of X-
tan X near X = 100, and gets considerably worse at 1000,
10,000 and so on).
APPENDIX 179
App end ix
These utility programs have been written in order to save you time.
The first two programs take all the work out of loading and running the
programs in this book from disk, not that this task is particularly arduous!
The music maker program helps you create your own tunes which you can
add to the listings of the games in this book.
The first two programs, "DISK LOAD", and "LOADER", are meant to
be used only if you have a disk drive. The idea is that once you have
loaded the program "DISK LOAD", and typed in RUN, then without
interruptin g the execution, you can load and run programs continuously.
These programs were written for the floppy disk that can be purchased
with this book. If you have not purchased the prerecorded disk, and want
to store some or all of the games in this book on your own floppy disk, you
will find these programs very useful.
The first program, called "DISK LOAD", is not essential. This simply
turns on different colors for the border and the screen and gives the
credits. If you do not like my choice of colors, you should experiment with
the settings in lines 230 to 300. "DISK LOAD" is used to load the
program that does all the work. This program is called "LOADER".
When you run "DISK LOAD" it stops with the message
LOAD"LO ADER" ,8
HIT RETURN AND THEN TYPE RUN
The curser is poised on the LOAD command so that when you press
RETURN, the program, "LOADER" is loaded into the computer. You then
type in RUN to execute "LOADER".
The program "LOADER" displays the chapters of the book, and the
games in each chapter. When you make a selection, say the game
"SIMON", the program stops with the message
LOAD"SIM ON" ,8
PRESS RETURN
The curser is positioned on the LOAD command so that when you press
the RETURN key, "SIMON" will be loaded.
In order to make an endless chain of loadings, you must alter every
STOP statement in each game program. For example, in "SIMON" you
must change line 305 from
305 STOP
to
305 LOAD"DI SK LOAD",8
180 APPENDIX
''Loa der''
100 PRINT "C"
110 Z=1:REM Z CONTROLS THE REPEAT DISPLA
Y IN CASE AN ENTRY IS NOT VALID
120 PRINT "THE CHAPTERS ARE:"
130 PRINT
140 PRINT II 1.CONCENTRATION GAMES"
150 PRINT II 2.WORD GAMES"
160 PRINT" 3.LOGIC AND STRATEGY GAMES"
170 PRINT II 4.ARITHME TIC GAMES"
180 PRINT II 5.GEOMETRY GAMES"
190 PRINT II 6.ALGEBRA GAMES"
195 PRINT II 7.ROOT FINDERS"
196 PRINT " 8.APPEND IX"
200 PRINT:PRI NT "TO LIST GAMES PRESS AN
UMBER 1 TO 8"
210 PRINT:PRI NT "PRESS S TO STOP"
220 GET A$:IF A$="" THEN 220
230 IF A$="S" THEN STOP
240 P=INT(VA L(A$)) :REM PIS THE VALUE OF
THE INPUT AND CONTROLS THE GOTO IN 200
250 IF P>0 AND P<9 THEN ON P GOTO 1000,2
000,3000 ,4000,500 0,6000,70 00,8000
255 REM:CONTROL COMES HERE WHEN ENTRY IS
NOT VALID
260 PRINT "WRONG ENTRY TRY AGAIN"
270 FOR T=1 TO 1000:NEXT T:ON Z GOTO 100
,300:REM WAITS WHILE 260 IS VIEWED
300 PRINT "C"
310 Z=2
320 IF P<8 THEN PRINT "THE GAMES IN CHAP
TER ";A$;" ARE:":PRI NT
325 IF P=8 THEN PRINT "THE APPENDIX PROG
RAMS ARE:":PRI NT
330 FOR I=1 TO N
340 PRINT STR$(I); ".";N$(I) ;REM THIS LIS
TS THE GAMES IN A CHAPTER
350 NEXT I
360 PRINT:PRI NT "TO LOAD PRESS A NUMBER
1 TO ";N
370 PRINT:PRI NT "PRESS S TO STOP, OR C T
"LOADER" 183
0 VIEW CHAPTERS"
380 GET C$:IF C$="" THEN 380
390 IF C$="S" THEN STOP
400 IF C$="C" THEN 100
410 Q=INT(VA L(C$))
420 IF 0>0 AND O<N+1 THEN 440
430 GOTO 260
440 PRINT "C":REM NORMALIZE SCREEN
445 POKE 53280,14:P OKE 53281,6:P RINT CHR
$(154)
450 REM:LOADING INSTRUCTIONS ARE HERE
460 PRINT "C":PRINT :PRINT:PR INT
470 PRINT "LOAD ";CHR$(34 );N$(Q);C HR$(34
);",8"
480 PRINT:PRI NT"PRESS RETURN";"OO"
490 STOP
999 REM:GAMES DATA IS LOADED INTO N$ BY
THESE SUBROUTINES
1000 N=5
1010 N$(1)="CONCENTRATION"
1020 N$(2)="FL ASH"
1030 N$(3)="KN IGHT"
1040 N$(4)="KNIGHTMARE"
1050 N$(5)="SIM ON"
1060 GOTO 300
2000 N=6
2010 N$(1)="ANAGRAMS I"
2020 N$(2)="ANAGRAMS II"
2030 N$(3)="HANGMAN"
2035 N$(4)="FI ND A WORD"
2040 N$(5)="EN IGMA I"
2050 N$(6)="EN IGMA II"
2060 GOTO 300
3000 N=8
3010 N$(1)="INV ADER"
3020 N$(2)="PR OBABILIT Y"
3030 N$(3)="SE A HUNT"
3040 N$(4)="VE RIFY"
3050 N$(5)="LO OSE CHANGE"
3060 N$(6)="NI M II"
3070 N$(7)="NI M III"
3080 N$(8)="TOW ERS OF HANOI"
3090 GOTO 300
4000 N=6
184 APPENDIX
''Music Maker''
10 PRINT "O":RESTORE
9000 REM:INITIALIZE ALL SETTINGS TO ZERO
9010 FOR L=54272 TO 54296:POKE L,0:NEXT
9020 REM:SET VOLUME TO MAXIMUM
9030 POKE 54296,15
9035 PRINT:PRINT
9040 PRINT "THE WAVEFORM, ATTACK/DECAY A
NO SUSTAIN/RELEASE SETTINGS ARE USED "
9050 PRINT "TO SYNTHESIZE INSTRUMENTS"
9055 PRINT:PRINT:PRINT"INPUT -1 TO STOP"
9056 PRINT:PRINT
9060 INPUT "WAVEFORM";W:IF W=-1 THEN STO
p
9061 IF W=65 THEN FOR I=54274T054288 STE
P 7:POKEI,255:POKEI+1,0:NEXT
9065 INPUT "ATTACK/DECAY";A:IF A=-1 THEN
STOP
9066 INPUT "SUSTAIN/RELEASE";S:IF S=-1 T
HEN STOP
9070 REM:SET THESE NUMBERS INTO EACH VOl
CE LOCATION
9080 FOR I=1 TO 3:V=54269+7*I:POKE V+1,A
:POKE V+2,S:NEXT I
9100 REM:GET CREATES A LOOP TERMINATED B
Y PRESSING A KEY
9101 PRINT "l'J"
9102 PRINT "PRESS ANY KEY TO STOP NOTE A
NO RESTART, PRESS RUN/STOP TO STOP"
9103 RESTORE
9110 GET AS:IF A$="" THEN 9130
9120 GOTO 10
9130 FOR I=1 TO 3:READ H(I) ,L(I) :NEXT I
9140 READ D
9150 IF D=-1 THEN RESTORE:GOTO 9130
9160 REM:SET VOICES
9170 FOR I=1 TO 3:V=54266+7*I:POKE V,H(I
) :POKE V-1 , L (I) :NEXT I
9175 FOR I=1 TO 3:POKE 54269+7*I,W:NEXT
9180 REM:DURATION
9190 FOR T=1 TO D:NEXT
"MUSIC MAKER" 193
Babalonians, 102 D
back-substitution, 13 7, 161
BARTER, vii, xii, 98, 99, 184, DATA,23,30,35,36, 123,133,
188, 189 134, 145, 190, 191, 193,
BASE, vii, xii, xiii, 101, 102, 103, 194, 195, 196
104, 105, 106, 107, 184, DEF FNF, 173
188, 189 DEF FNG, 170
basic polynomials, 32 DETONATION, viii, xii, xiii, 122,
binary, 90, 102, 103, 104 124, 129, 140, 141, 184,
binomial coefficients, 65 188, 189
binomial expansion, xii, 64 differentiate, 106
Binomial, 64 DIM, 25, 173, 191
197
198 INDEX
G J
vectors, 1 7 3 y
VERIFY, vii, xii, 70, 72, 183, 187,
189 YOUR NUMBER IS UP, viii, xii, xiii,
104, 105, 106, 164, 184,
188, 189
w
z
WARP, viii, xii, 143, 146, 184,
zero, xiii, 32, 140, 164, 171,
188, 189
173, 176, 177
------------------------------
203
Instructions For
Making A Back-Up
Copy Of Your Brain
Games Diskette
1. Insert a blank disk into the disk drive. Be sure to use a disk without
anything on it that you wish to keep.
2. Type:
OPEN15,8,15
then press RETURN. Type:
PRINT#15,"N:BRAIN-BACKUP,64"
then press RETURN. This operation will blank and reformat your disk
and will take a few minutes.
3. Type:
CLOSE15
Press RETURN. Type:
LOAD"$" ,8
Press RETURN. Type:
LIST
and press RETURN. At this point you should have on your screen:
0 "BRAIN-BACKUP "64 2A
664 BLOCKS FREE
4. Now you are ready to copy the programs from the BRAIN GAMES
disk to your back-up disk. This will involve LOADing each of 41
programs from the BRAIN GAMES disk into the computer and then
SAVEing each on your disk.
Follow these steps:
a. Remove your back-up disk.
b. Insert the BRAIN GAMES disk.
c. Type: LOAD"CONCENTRATION",8 (Press RETURN)
d. Remove the BRAIN GAMES disk.
e. Insert your back-up disk.
f. Type: SAVE"CONCENTRATION",8 (Press RETURN)
204
Follow the above steps for each of the programs listed on the next
page. Be sure to type in the names exactly, including periods and
spaces. For your convenience, a checklist is provided.
If you find you have misspelled a program name on your back-up disk,
you can correct the program spelling by the following procedure:
1. Insert your back-up disk.
2. Type:
OPEN15,8,15
Press RETURN.
3. Type:
PRINT#15,"R:N EWNAME=OLD NAME"
Press RETURN. NOTE: In place of NEWNAME you should type the
correctly spelled program name, and in place of OLDNAME you type
the misspelled program name.
4. Type:
CLOSE15
It is recommended that you use your back-up disk and put the original
BRAIN GAMES disk in a safe place.
205
STEPS
PROGRAM a b c d e
"CONCENTRATION"
"FLASH"
"KNIGHT"
"KNIGHTMARE"
"SIMON"
"ANAGRAMS I"
"ANAGRAMS II"
"HANGMAN"
"FIND A WORD"
"ENIGMA I"
"ENIGMA II"
"INVADER"
"PROBABILITY"
"SEA HUNT"
"VERIFY"
"LOOSE CHANGE"
"NIM II"
"NIM Ill"
"TOWERS OF HANOI"
"BARTER"
"BASE"
"YOUR NUMBER IS UP"
"CRYPTIC"
"HUMAN ARITHMETIC"
"JUGS"
"DETONATION"
"QUEST"
"TREK"
"U-BOAT"
"WARP"
"MONKEY PUZZLE"
"OBSCURE AGES"
"MORE OBSCURE AGES"
"MUCH MORE OBSCURE AGES"
"PRODUCT AND SUMS"
"RALLY"
"FIXED-POINT"
"BRACKET"
"DISK LOAD"
"LOADER"
"MUSIC MAKER"
207