RAINBOW2MASTERM$28 $27 $26 $SWAP $25 $24 $23 $MAGICSQ$22 $HILO $21 $20 $19 $MENU $!BOOT $ 3 #9#2#71#70#d,#%#7$#7####O##7#7
#!,*BASIC
PAGE=&1900
*FX21
CLOSE#0:CHAIN"MENU"
*FX200,1
7
*FX11,0
( *FX15
2*KEY10CHAIN"MENU"|L|M
13 l%+3,p%+t%+3)156c2%
! G%=138 p%=p%+1: p%>i% p%=1
! G%=139 p%=p%-1: p%=0 p%=i%
$ G%<>13 l%+3,p%+t%+3)157c5%
G%=13:*FX4
*FX12
*FX11,50
=p%
p%
menuo%$%%%%%h1%q2%z3%4%5%RAINBOW BOOK OF BASIC PROGS 2$!Fast Brakesd Temperatures%36 $35 $34 $33 $32 $31 $30 $STICKS $29 $ H #7#7#7#7#7#7#7#N #
7
23;8202;0;0;0;
TITLE$="PICKUP STICKS"
(
title
2T"Here is another chance to match wits with your computer - and perhaps win."
<"Imagine that there are 21 brightly coloured sticks lying in three rows. With each turn, not less than one and not more than seven sticks must be 'picked up' and removed from the game."
F" You and the computer take turns at picking up. The object of the game is toforce your opponent to take away the last stick. The computer will try to beat you in turn by making you pick up"
P"the last stick."
Z
space
d" The best strategy for winning this game is to work backward from the last remaining stick. For your last turn you would like to have anything from two to eight sticks available (so you can take"
n"away from one to seven and so leave the computer with only a single stick). Therefore, you want to make sure that the computer ends up with at least nine sticks on its second to last turn."
x" It sounds confusing at first, but if you keep working backwards like this you will find that you can win with the first move of the game if you are clever. Remember - the computer always"
P"asks you to go first so you should be able to beat it most of the time."
space
TITLE$="HINT"
title
"Draw three rows with seven sticks in each and cross off the ones which are removed as you play. It will help you tokeep track of the ones which remain."
*FX15,1
<1,23);"Press the SPACE BAR to play the game.": =32
"STICKS"
title
L=(TITLE$)
20-L/2);TITLE$
20-L/2);L,"_")
"
,space
6=1,23);"Press the SPACE BAR for the next page.": =32
@:title:
(2468:<>@BDFHJLdnx
d PICKUP
n
DLD
x " PICKUP STICKS"
T=4: DxE: dpJ
S=21: L=7
dpJ::
Z$=(S)
"TOTAL IS ";Z$
T=1: DxE
: "YOUR GO ";
TtH
K>L tV@
K<=0 TXA
K>S tV@
S=S-K
S>0
7
"NON-GAME PROGRAM"
"NOT INCLUDED"
(
MENU"|L|M
R "TOO HIGH"
J T=1: DxE
T
dH@
^:
h G>6 "DREADFUL!!"
r G<7 G>4 "NOT BAD!"
| G<5 "VERY GOOD!!"
"::"YOU TOOK ";(G);" TRIES"
BBC SUBROUTINES
L; 5: 19,0,4;0;:W=20:D=32:F=8:23;8202;0;0;0;: tpD:
: 0,8);:
R=(N):
x Z=1 1000*T:Z:
G$=:
@
K$=(0):
X,Y);:
X);:
l (11);:
(9);:
4 K:
K$:
7:
` 1,-15,Z,2:
R$=(R+64):
(P$=KDJA
S=0 TlA
S=S+K
: "SILLY": DxE: tV@
" T=2: DxE: tZA
,: "YOU TOOK LAST STICK"
6: "YOU LOSE!!"
@
dtA
J
Z$=(S)
T: "TOTAL IS ";Z$
^ T=1: DxE
h S<>1 tPA
r: "I HAVE TO TAKE "
|: "LAST STICK"
: "YOU WIN!!": dtA
/ R=S-((S-1)/(L+1))*(L+1)-1: R>0 tdA
! N=S-1: TTE: R>L tZA
Z$=(R)
: "I TAKE AWAY ";Z$
S=S-R
Z$=(S)
"TOTAL IS ";Z$
T=3: DxE: dpJ
tV@
BBC SUBROUTINES
L; 5: 19,0,4;0;:W=20:D=32:F=8:23;8202;0;0;0;: tpD:
: 0,8);:
R=(N):
x Z=1 1000*T:Z:
G$=:
@
K$=(0):
X,Y);:
X);:
l (11);:
(9);:
4 K:
K$:
7:
` 1,-15,Z,2:
R$=(R+64):
(P$=K$,P,1):
ThJ:A=(P$):
:
T V$(26):
W$(60):
GG=(G$):
(G$):
60):
GG=(G$):
0):
GG=(G$):
GG=(G$):
GG=(G$):
):
GG=(G$):
):
GG=(G$):
=(G$):
=(G$):
$(60):
GG=(G$):
$(60):
GG=(G$
7
"NON-GAME PROGRAM"
"NOT INCLUDED"
(
DxE: dpJ
S=21: L=7
dpJ::
Z$=(S)
"TOTAL IS ";Z$
T=1: DxE
: "YOUR GO ";
TtH
K>L tV@
K<=0 TXA
K>S tV@
S=S-K
S>0
7
"NON-GAME PROGRAM"
"NOT INCLUDED"
(
DxE: dpJ
S=21: L=7
dpJ::
Z$=(S)
"TOTAL IS ";Z$
T=1: DxE
: "YOUR GO ";
TtH
K>L tV@
K<=0 TXA
K>S tV@
S=S-K
S>0
7
"NON-GAME PROGRAM"
"NOT INCLUDED"
(
DxE: dpJ
S=21: L=7
dpJ::
Z$=(S)
"TOTAL IS ";Z$
T=1: DxE
: "YOUR GO ";
TtH
K>L tV@
K<=0 TXA
K>S tV@
S=S-K
S>0
7
"NON-GAME PROGRAM"
"NOT INCLUDED"
(
DxE: dpJ
S=21: L=7
dpJ::
Z$=(S)
"TOTAL IS ";Z$
T=1: DxE
: "YOUR GO ";
TtH
K>L tV@
K<=0 TXA
K>S tV@
S=S-K
S>0
7
"NON-GAME PROGRAM"
"NOT INCLUDED"
(
DxE: dpJ
S=21: L=7
dpJ::
Z$=(S)
"TOTAL IS ";Z$
T=1: DxE
: "YOUR GO ";
TtH
K>L tV@
K<=0 TXA
K>S tV@
S=S-K
S>0
7
"NON-GAME PROGRAM"
"NOT INCLUDED"
(
DxE: dpJ
S=21: L=7
dpJ::
Z$=(S)
"TOTAL IS ";Z$
T=1: DxE
: "YOUR GO ";
TtH
K>L tV@
K<=0 TXA
K>S tV@
S=S-K
S>0 $,P,1):
ThJ:A=(P$):
:
T V$(26):
W$(60):
GG=(G$):
z@H@
(26):
W$(60):
GG=(G$):
V$(26):
W$(60):
GG=(G$):
W$(60):
GG=(G$)
7
23;8202;0;0;0;
TITLE$="MAGIC SQUARES"
(
title
2C"Big Harry and Kevin were sitting in the Rolls one afternoon."
<"'Kevin my son', said Harry, blowing a cloud of cigar smoke into Kevin's face, 'business is far too slow. If things don't pick up soon we'll be needing a new line of work. Know what I mean?'."
FC"'Right Boss', kevin gagged,'I'll get onto it right away'."
PT" The next night Kevin was wearing a biggrin as he slumped down in the Rolls."
Z"'Boss. You'll love this. I've found a jeweller's shop that's just perfect. Hisvaluable stuff is all in an old safe - as big as a room it is. And the lock's a piece of cake'."
d
space
n"'My uncle Fred, who works there, says ithas a 16 number combination. You turn the dial four numbers to the left. Four to the right. Then four to the left and four right again. The only trouble is"
x"that old Fred's memory is shot - used tobox in the ring as a lad. He says he canonly remember seven of the numbers. Funny though, he noticed that all the numbers of the combination make my age."
m"No matter if you add them up and down, across or sideways they always come to the same number - 34!'"
@" Big Harry looked doubtful and blew more cigar smoke."
K"'This had better be good Kevin, or I'll have your hide as a duster'."
space
I"He flicked at an imaginary speck on the inlaid rosewood panelling."
" Kevin still has his hide. The drawing below shows the scrap of paper Uncle Fred gave Kevin with the seven numbers he could remember. What was the safe's combination?"
:
"16 - 3 13"
"- 11 - - "
"- 7 6 - "
" 4 - - - "
*FX15,1
<1,23);"Press the SPACE BAR to play the game.": =32
"MAGICSQ"
title
"
,L=(TITLE$)
6 20-L/2);TITLE$
@ 20-L/2);L,"_")
J
T
^space
h=1,23);"Press the SPACE BAR for the next page.": =32
r:title:
(2<FPZdnx",6@JT^h
d MAGIC
n
DLD
x " MAGIC SQUARE"
T=2: DxE: dpJ
N=1: C=1
A(4,4)
C(4,4)
J=1 4
K=1 4
C(J,K)=0
K
J
J=1 4
K=1 4
A(J,K)=(J-1)*4+K+N-1
K
J
J=1 2
" Z=A(J,J):
7
"NON-GAME PROGRAM"
"NOT INCLUDED"
(
DxE: dpJ
S=21: L=7
dpJ::
Z$=(S)
"TOTAL IS ";Z$
T=1: DxE
: "YOUR GO ";
TtH
K>L tV@
K<=0 TXA
K>S tV@
S=S-K
S>0 A(J,J)=A(5-J,5-J)
" A(5-J,5-J)=Z: Z=A(J,5-J)
,$ A(J,5-J)=A(5-J,J): A(5-J,J)=Z
6 J
@ C(1,1)=A(1,1)
J C(1,3)=A(1,3)
T C(1,4)=A(1,4)
^ C(2,2)=A(2,2)
h C(3,2)=A(3,2)
r C(3,3)=A(3,3)
| C(4,1)=A(4,1)
dpJ
X=5: Y=0: tdF
"A B C D"
J=1 4
Y=2+3*(J-1)
K=1 4
" X=4*K+1: C(J,K)>9 X=X-1
tdF:; C(J,K)
K
J
X=0
J=1 4
Y=2+3*(J-1): tdF: (J);
J: C=0 t|B
/ X=0: Y=13: tdF: "COLUMN ROW NUMBER"
X=0: Y=14: tdF
& tXH: C$=K$
0 C$="A" C=1
: C$="B" C=2
D C$="C" C=3
N C$="D" C=4
X X=8: tdF: TtH: R=K
b X=15: tdF: TtH: N=K
l A(R,C)=N C(R,C)=A(R,C)
v C=0
J=1 4
K=1 4
C(J,K)=0 C=1
K
J
tFA
::"CORRECT!":
BBC SUBROUTINES
L; 5: 19,0,4;0;:W=20:D=32:F=8:23;8202;0;0;0;: tpD:
: 0,8);:
R=(N):
x Z=1 1000*T:Z:
G$=:
@
K$=(0):
X,Y);:
X);:
l (11);:
(9);:
4 K:
K$:
7:
` 1,-15,Z,2:
R$=(R+64):
(P$=K$,P,1):
ThJ:A=(P$):
:
T V$(26):
W$(60):
GG=(G$):
) ) K`[(
7
"NON-GAME PROGRAM"
"NOT INCLUDED"
(
DxE: dpJ
N=1: C=1
A(4,4)
C(4,4)
J=1 4
K=1 4
C(J,K)=0
K
J
J=1 4
K=1 4
A(J,K)=(J-1)*4+K+N-1
K
J
J=1 2
" Z=A(J,J):
7
"NON-GAME PROGRAM"
"NOT INCLUDED"
(
DxE: dpJ
N=1: C=1
A(4,4)
C(4,4)
J=1 4
K=1 4
C(J,K)=0
K
J
J=1 4
K=1 4
A(J,K)=(J-1)*4+K+N-1
K
J
J=1 2
" Z=A(J,J):
7
23;8202;0;0;0;
TITLE$="SWAP"
(
title
2"In this program the computer presents you with a list of six numbers that are in jumbled order. You must rearrange them into numerical order from left to right so that they read:"
<:"10 20 30 40 50 60":
Fs" With each move you must tell the computer how many numbers to reverse, counting from left to right."
P
space
ZK"For example, you may find that the jumbled order is as follows:"
d:"30 20 10 40 50 60":
n" The computer asks how many need to be reversed. If your answer is three then the first three numbers will be swapped around and the new sequence will look like this:"
x:"10 20 30 40 50 60":
$"The numbers are now in order."
space
" Obviously you cannot reverse only one number since that will not change its position. The most you can reverse is six - the entire line."
i" The object of the game is to unscramble the jumbled numbers in as fewmoves as possible."
" The best strategy to use is to bring the largest numbers to the front of the row, and then to swap them into their correct position."
space
TITLE$="HINT"
title
"The formula 2N-3 (where there are N numbers in the row) predicts the total number of moves you would need to win the game if you yourself were a computer. Of course you should be able"
-"to do much better than a mere machine!"
*FX15,1
<1,23);"Press the SPACE BAR to play the game.": =32
"SWAP"
title
"
,L=(TITLE$)
6 20-L/2);TITLE$
@ 20-L/2);L,"_")
J
T
^space
h=1,23);"Press the SPACE BAR for the next page.": =32
r:title:
(2<FPZdnx",6@JT^h"`
d
SWAP
n
DLD
x " SWAP"
T=2: DxE
N(6)
I=1 6: N(I)=10*I: I
N=6: I=1 6: TTE
+ T=N(I): N(I)=N(R): N(R)=T: I: M=0
! M=M+1: T=0.5: DxE: dpJ
( F=0: I=1 6: N(I)<>10*I F=1
I
: "JUMBLED ORDER IS": Y=4
I=1 6: X=3*I-2: tdF
(N(I)): I
% X=0: Y=7: tdF: F=0 TlA
"REVERSE HOW MANY? ";
TtH
+ I=1 (K/2): T=N(I): N(I)=N(K+1-I)
N(K+1-I)=T: I
"
tt@
,#: "YOU WIN IN ";(M);" MOVES"
6 ::
BBC SUBROUTINES
L; 5: 19,0,4;0;:W=20:D=32:F=8:23;8202;0;0;0;: tpD:
: 0,8);:
R=(N):
x Z=1 1000*T:Z:
G$=:
@
K$=(0):
X,Y);:
X);:
l (11);:
(9);:
4 K:
K$:
7:
` 1,-15,Z,2:
R$=(R+64):
(P$=K$,P,1):
ThJ:A=(P$):
:
T V$(26):
W$(60):
GG=(G$):
7
"NON-GAME PROGRAM"
"NOT INCLUDED"
(
N(6)
I=1 6: N(I)=10*I: I
N=6: I=1 6: TTE
+ T=N(I): N(I)=N(R): N(R)=T: I: M=0
! M=M+1: T=0.5: DxE: dpJ
( F=0: I=1 6: N(I)<>10*I F=1
I
: "JUMBL
7
"NON-GAME PROGRAM"
"NOT INCLUDED"
(
N(6)
I=1 6: N(I)=10*I: I
N=6: I=1 6: TTE
+ T=N(I): N(I)=N(R): N(R)=T: I: M=0
! M=M+1: T=0.5: DxE: dpJ
( F=0: I=1 6: N(I)<>10*I F=1
I
: "JUMBL
7
23;8202;0;0;0;
TITLE$="MASTERMIND"
(
title
2~"In this puzzle the computer picks a three-digit number at random using digits between one and nine (not zero)."
<"You have 20 guesses to find out what thenumber is. Because there are 888 numbers to choose from it takes a littlecunning to work out what the right one is."
F" With each guess you must select a three digit number. The computer tells you how many digits are right and how many are wrong, and whether any of the right ones are in the correct position"
P"in the number."
Z
space
d" For example, if the correct number is 135 and you guessed 259, the computer would report that you had one right number but in the wrong position. If youhad guessed 925 then it would have"
n8"reported one right number in the correctposition."
x" The best strategy with this puzzle is to eliminate as many wrong numbers as possible before trying to find the correct position of the right ones."
space
TITLE$="VARIATIONS"
title
q"You should be able to solve the puzzle in far less than 20 guesses once you have tried it a few times."
"In line 250, change:"
-"FOR I=1 TO 20into:FOR I=1 TO 10and"
-"see if you can still beat the machine."
*FX15,1
<1,23);"Press the SPACE BAR to play the game.": =32
"MASTERM"
title
L=(TITLE$)
" 20-L/2);TITLE$
, 20-L/2);L,"_")
6
@
Jspace
T=1,23);"Press the SPACE BAR for the next page.": =32
^:title:
fITLE$
VARIATIONSxCtitler space,6@JT^Brakesd Temperaturese SPACE B%
the next page.": =32
r:title:
ITLE$HINTtitlespaceX",6@JT^h"`
d MASTER
n
DLD
x " MASTERMIND"
T=4: DxE: dpJ
A(3)
B(3)
Y1=0: T1=255
M=0: I=1 3
N=9: TTE
A(I)=R
I-1=0 dp@
F=0: J=1 I-1
A(I)=A(J) F=1
J: F=1 t~@
M=10*M+A(I): I
I=1 20
dpJ
: "GUESS NUMBER ";(I)
: "ENTER GUESS ";
"
TtH
, K<111 K>999 TDA
6 B(1)=(K/100)
@! B(2)=((K-100*(K/100))/10)
J B(3)=K-10*(K/10)
T C=0: D=0
^
J=1 2
h A(J)<>B(J+1) D|A
r C=C+1
| A(J+1)<>B(J) tPA
C=C+1
J
A(1)<>B(3) tnA
C=C+1
A(3)<>B(1) dBA
C=C+1
J=1 3
A(J)<>B(J) d`A
D=D+1
J
D=3 DbB
C=0 THB
: (C);" WRONG POSITION"
D=0 T\B
: (D);" CORRECT"
C+D<>0 TpB
&: "NOTHING CORRECT"
0 T=2: DxE
: I
D:"THAT'S 20 GUESSES"
N:"NUMBER WAS ";(M)
X
DlB
b: "YOU GOT IT!"
l
BBC SUBROUTINES
L; 5: 19,0,4;0;:W=20:D=32:F=8:23;8202;0;0;0;: tpD:
: 0,8);:
R=(N):
x Z=1 1000*T:Z:
G$=:
@
K$=(0):
X,Y);:
X);:
l (11);:
(9);:
4 K:
K$:
7:
` 1,-15,Z,2:
R$=(R+64):
(P$=K$,P,1):
ThJ:A=(P$):
:
T V$(26):
W$(60):
GG=(G$):
0 @z (@(@11S@@S