P63 Number of Days


It can be interesting in many everyday problems to calculate the number of days between two dates. This program does this by calculating the number of days from day 0 of the Gregorian Calendar for each date and then calculating the number of days between the two dates.

COMMANDS

Key in program and type RUN.
Enter Gregorian dates when prompted.

  100 REM Program  - Number of Days
  110 MODE 6
  120 PRINT "Enter first date of interest"
  130 INPUT "Day (1-31) " day_1
  140 INPUT "Month (1-12) " month_1
  150 INPUT "Year (eg 1982) " year_1
  160 PRINT '''"Enter second dat of interest"
  170 INPUT "Day (1-31) " day_2
  180 INPUT "Month (1-12) " month_2
  190 INPUT "Year (eg 1982) " year_2
  200 no_of_days=FN_days(day_2,month_2,year_2) - FN_days(day
_1,month_1,year_1)
  210 PRINT ''"The number of days between the two"
  220 PRINT "dates is "no_of_days
  230 END
  240 DEF FN_days(d,m,y)
  250 RESTORE
  260 FOR I=1 TO m
  270   READ days_this_year
  280 NEXT I
  290 DATA 0,31,59,90,120,151,181,212,243,273,304,334
  300 days_this_year=days_this_year+d
  310 days_since_0=days_this_year + y*365 + INT(y/4) +1 - IN
T(y/100) + INT(y/100)
  320 IF (y MOD 4)=0 AND (m<3) THEN days_since_0=days_since_
0 - 1
  330 =days_since_0


P64 Digital Clock


This program exhibits a digital clock on the screen.

COMMANDS

Key in program and type RUN.
Enter time when requested.


  100 REM Program P64 - Digital Clock
  110 MODE 2
  120 @%=2
  130 INPUT "Hour "hour
  140 INPUT "Minute " min
  150 INPUT "Second " sec
  160 CLS
  170 VDU 23,1,0;0;0;0;
  180 TIME=0
  190 PRINT TAB(6,12)":"
  200 PRINT TAB(9,12)":"
  210 REPEAT
  220   TIME=0
  230   hour=hour MOD 24
  240   REPEAT
  250     IF hour>0 THEN TIME=0
  260     PRINT TAB(4,12) hour
  270     hour=hour+1
  280     min=min MOD 60
  290     REPEAT
  300       IF min>0 THEN TIME=0
  310       PRINT TAB(7,12) min
  320       min=min+1
  330       sec=sec MOD 60
  340       REPEAT
  350         IF sec>0 THEN TIME=0
  360         PRINT TAB(10,12) sec
  370         sec=sec+1
  380         REPEAT UNTIL TIME=100
  390       UNTIL sec=60
  400     UNTIL min=60
  410   UNTIL hour=24
  420 UNTIL 0


P65 Kitchen Timer


A useful program for the kitchen here, the program displays the time that has yet to elapse before your meal is ready. When the timer reaches zero, an alarm sounds.

COMMANDS

Key in program and type RUN.
Enter setting when requested.

  100 REM Program P65 - Kitchen Timer
  110 MODE6
  120 @%=3
  130 PRINT TAB(12,12)"K I T C H E N"
  140 PRINT TAB(12,14)"  T I M E R"
  150 Z=INKEY(300)
  160 MODE 6
  170 PRINT TAB(5,5)"What setting do you require";
  180 INPUT TAB(5,6)"Hours="hours
  190 INPUT TAB(5,7)"Minutes="mins
  200 INPUT TAB(5,8)"Seconds" secs
  210 IF secs>0 THEN secs=secs-1
  220 MODE 2
  230  
  240 REPEAT
  250   REPEAT
  260     REPEAT
  270       TIME=0
  280       REPEAT UNTIL TIME=100
  290       PRINT TAB(5,12) hours,mins,secs
  300       secs=secs-1
  310     UNTIL secs=-1
  320     mins=mins-1
  330     secs=59
  340   UNTIL mins=-1
  350   hours=hours-1
  360   mins=59
  370 UNTIL hours=-1
  380  
  390 SOUND 1,-15,53,-1


P66 Recipes


In this program, I have recorded some of my favourite recipes. Therese are based on recipes in "Favourite Family Cookbook" by Norma Macmillan, Octopus (1978).

Notice the use of the RESTORE statements in lines 210 and 300. This is an example of direct accessing of data. We do not read through the whole of the recipe list to find the one required, but restore the DATA pointer to the correct line. You can use this basic structure to build up your own recipes.

Although I have included my own recipes, it would perhaps be better if you replaced my data statements with your own.

COMMANDS

Key in program and type RUN.
Follow the menus as presented.

  100 REM Program P66 - Recipes
  110 MODE 6
  120 PRINT '''"      R E C I P E  M E N U"
  130 PRINT '''
  140 PRINT "        1. Hors d'Oeuvres"
  150 PRINT "        2. Soups"
  160 PRINT "        3. Fish"
  170 PRINT "        4. Meat"
  180  
  190 PROCrubric
  200 section=choice%*1000
  210 RESTORE section
  220 READ menu_title$
  230 CLS
  240 PRINT '''"      "menu_title$'''
  250 FOR I=1 TO 4
  260   READ recipe_name$
  270   PRINT I". "recipe_name$
  280 NEXT I
  290 PROCrubric
  300 RESTORE section+choice%*10
  310 CLS
  320 READ recipe_name$
  330 PRINT recipe_name$
  350 PRINT ''
  360 ingredient$=""
  370 REPEAT
  380   PRINT ingredient$
  390   READ ingredient$
  400 UNTIL ingredient$="end"
  410 INPUT '"Another",ans$
  420 IF LEFT$(ans$,1)="Y" THEN RUN ELSE END
  430  
  440 DEF PROCrubric
  450 PRINT '''"Enter the appropriate number for the"
  460 PRINT "recipe of your choice";
  470 INPUT "  "choice%
  480 ENDPROC
  490  
  500  
 1000 DATA H o r s   d' O e u v r e s,Kipper pate,Egg Mayonn
aise,Mushrooms a la grecque,Grilled Grapefruit
 1010 DATA K i p p e r   p a t e,2 tblesp unsalted butter,1/
2lb kipper fillets,1 cup cream cheese,1/2 garlic clove-crush
ed,juice of 1/2 lemon,black pepper,,,
 1011 DATA Melt butter in frying pan,add kippers,cook till s
oft,remove and cool then flake fish
 1012 DATA Blend fish cheese etc till smooth,Serve chilled w
ith pepper,end
 1020 DATA E g g  M a y o n n a i s e,4 large lettuce leaves
,8 sprigs watercress,4 eggs - hard boiled and halved, 1 1/4 
cups mayonnaise,pinch of paprika,,,
 1021 DATA Put a lettuce leaf on each of 4 plates.,Add 2 spr
igs of watercress to each,Place eggs in centre flat side dow
n.,Pour over mayonnaise and add paprika,end,
 1030 DATA Mushrooms a la grecque,1 1/4 cups water,small oni
on - chopped,2 tblesp olive oil,1 teasp tomato paste,salt n 
pepper,bouquet garni and lemon juice
 1031 DATA 3 cups small button mushrooms,parsley to garnish
 1032 DATA Put all except mushrooms and garnish,into saucepa
n and simmer for 5 minutes.,Add mushrooms and simmer for 10 
minutes.,Remove mushrooms.
 1033 DATA Boil liquid until 3-4 tblesp left.,Pour over mush
rooms and serve with,parsley,end,
 1040 DATA G r i l l e d   G r a p e f r u i t,2 large grape
fruits - halved,4 teasp medium sherry,4 tblesp brown sugar,1
 tblesp butter - cut into 4 pieces,,,
 1041 DATA Loosen segments of grapefruit and,remove seeds. D
rain halves onto kitchen,paper for a few minutes.,Place grap
efruit halves in grill 
 1042 DATA Top each with butter - grill until,bubbling,end,
 1050 DATA Put a lettuce leaf on each of 4 plates.,Add 2 spr
igs of watercress to each,Place eggs in centre flat side dow
n.,Pour over mayonnaise and add paprika,end,
 2000 DATA S o u p s,Borsch,Pea Soup,Oxtail Soup,French Onio
n Soup
 2010 DATA B o r s c h,2 tblesp butter,large onion - peeled 
and sliced,large carrot - peeled and grated,2 large cooked b
eetroot - sliced
 2011 DATA 1/2 small head red cabbage - shredded,1 tblsp tom
ato paste,1 tblsp vinegar & 1 tblsp sugar,salt n pepper,5 cu
ps beef stock,1 1/4 cups sour cream to serve,,
 2012 DATA Melt butter in pan and cook vegetables,gently for
 5 minutes. Stir in other,ingredients and simmer for 20-30 m
ins,until veg are tender. Serve with cream,end,
 2020 DATA P e a   S o u p,2 tblesp butter & 1 tblesp olive 
oil,1 onion & 2 celery stalks - chopped
 2021 DATA 2 cups shelled peas,1 small ham bone,2 cups chick
en stock,1 tblsp cornflour,1 1/4 cups milk,salt n pepper,,
 2022 DATA Melt butter and oil in pan - fry celery,and onion
. Cook peas for 5 mins. Add,bone & stock then boil for 40 mi
ns.,Remove bone and puree soup.,Dissolve flour in milk and a
dd to soup.,Simmer until thick. Serve hot.,end,
 2030 DATA O x t a i l   S o u p,4 tblspns oil & 4 1/2 pts w
ater,1 oxtail - cut into pieces,2 onions 2 carrots 2 celery 
- chopped
 2031 DATA1 turnip chopped,salt n pepper,1 14  oz can of tom
atoes,2 tblsp flour & 4 tblsp sherry,,
 2032 DATA Brown oxtail and fry veg till soft. Add to water 
with salt n pepper. Simmer for,4 hours. Remove oxtails and c
ut meat,from bones. Remove fat from soup and,return meat. Th
icken with sherry and,flour. Serve hot.,end,
 2040 DATA F r e n c h   O n i o n   S o u p,2 tblspn butter
 & 2 tblspn olive oil,1 garlic clove - crushed,3 large slice
d onions,5 cups beef stock
 2041 DATA salt n pepper,8-12 slices French bread,3/4 cup ch
eese,,
 2042 DATA Fry garlic and onions for 20 mins,do not brown to
o much. Simmer with salt n pepper for 30 mins.,Toast bread.,
Serve soup hot with toast and cheese,end,
 3000 DATA F i s h,Trout with Almonds,Salmon Steaks,Finnan H
addie,Scallops and Bacon
 3010 DATA T r o u t   w i t h   A l m o n d s,1/4 cup plain
 flour,salt n pepper,4 large trout - cleaned,1/3 cup butter,
1/2 cup almond flakes,2 teaspn lemon juice,lemon and parsley
 to garnish,,
 3011 DATA Mix flour with salt n pepper and coat,the trout. 
Melt butter in pan and brown,trout quickly on both sides. Co
ok trout,until tender. Remove fish and keep hot.
 3012 DATA Cook almonds in pan until golden.,Stir in lemon j
uice. Pour liquid and,almonds over fish and garnish.,end,
 3020 DATA S a l m o n   S t e a k s,4 salmon steaks,1/4 cup
 butter cut into 4,4 of - 1/2 bay leaf:onion slices,4 of - s
ilver lemon rind:thyme sprig,4 of - parsley sprig: salt n pe
pper,
 3021 DATA Divide ingredients into individual,portions. Wrap
 each in foil and bake in,a moderate oven (180 C:350 F:Gas M
ark 4,for 15-20 mins. Serve steaks hot without herbs.,end,
 3030 DATA F i n n a n   H a d d i e,1 1/2 lb smoked haddock
 - chopped,1 1/4 cups milk,2/3 cup single cream,2 tblsp butt
er,pepper,6 eggs,,
 3031 DATA Place fish in baking dish. Put milk,and cream and
 butter in pan and heat,until butter is melted. Pour over fi
sh.,Bake in moderate oven(180 C:350 F:Gas,Mark 4) for 20 min
s.
 3032 DATA Poach eggs 5 mins before fish is ready.,Top fish 
mixture with eggs and serve.,end,
 3040 DATA S c a l l o p s   a n d   B a c o n,16-20 shelled
 scallops,salt n pepper and lemon juice,16-20 bacon slices,,
 3041 DATA Sprinkle scallops with salt n pepper,and lemon ju
ice. Stretch bacon rashers,with flat knife. Wrap rasher roun
d each,Scallop and secure with cocktail stick.,Grill slowly 
till cooked - 5 mins and,serve with tartare sauce.,end,
 4000 DATA M e a t,Neapolitan Steak,Wiener Schnitzel,Lamb Cu
rry,Pork 'n Orange
 4010 DATA N e a p o l i t a n   S t e a k,4 sirloin steaks,
3 cups peeled n chopped tomatoes,2 tblsp olive oil,2 chopped
 garlic cloves,1 tblsp chopped parsley,1/2 teasp dried orega
no :1 teasp sugar,salt n pepper,,
 4011 DATA Boil toms oil garlic parsley sugar,salt n pepper 
and simmer for 5 mins.,Grill steaks and pour sauce over.,Ser
ve hot.,end,
 4020 DATA W i e n e r   S c h n i t z e l,4 veal escalopes 
pounded thin,juice of 2 lemons,salt n pepper and large beate
n egg,1 cup dry breadcrumbs,3 tblsp butter,lemon wedges to g
arnish,,
 4021 DATA Marinate veal in lemon with salt n,pepper for 1 h
our. Dip veal in egg and,coat with breadcrumbs. Fry veal in,
butter till golden brown.,end,
 4030 DATA L a m b   C u r r y,2lb lean lamb cubed,2/3 cup y
oghurt :2 teasp garam masala,1 tblsp curry powder,2 tblsp bu
tter :2 tblsp oil,2 chopped onions : crushed garlic clove,sa
lt n pepper n lemon juice
 4031 DATA 2/3 cup dried fruit : 2 tblsp almonds,,
 4032 DATA Mix yoghurt with garam masala and curry,Add lamb 
cubes and marinate for 4 hours,Fry onions and garlic till so
ft. Stir,in lamb + yoghurt & salt n pepper and,lemon juice. 
Cook for 5 mins then add
 4033 DATA fruit and almonds. Simmer till tender,end,
 4040 DATA P o r k   'n   O r a n g e,1/4 cup plain flour : 
salt n pepper,1 1/2lb pork fillet cut into cubes,2 tblsp but
ter : small onion chopped,1 chopped green pepper no pith or 
seeds,grated rind and juice of 2 oranges
 4041 DATA 1 tblespn Worcestershire sauce,2/3 cup beef stock
,1 peeled segmented orange,,
 4042 DATA Mix flour salt n pepper in bag. Add pork cubes an
d shake to coat. Fry onion,and pepper in butter till soft. B
rown,pork. Stir in orange rind and juice,add stock and sauce
. Simmer for 10 mins,add orange segs and cook for 2 mins
 4043 DATA Serve hot.,end,
 5000 REM End of program data.


P67 Encoder


This program can be used to code a secret message. The system used for the encoding is very simple. You are asked for a key word, the characters of which are used to offset the characters of the secret message. The program uses all the printable characters of the ELECTRON, so that characters such as space, full stop and comma, etc are also encoded. The encoding routine is held in lines 420 to 460.

EXAMPLE

MESSAGEABCD
KEY WORD12
SECRET CODE ISRTTY

Note the use of VDU21 and VDU6 to switch screen on and off.

COMMANDS

Key in program and type RUN.
Type secret message,finish with RETURN. (Note that it will not appear on the screen.)
Type in secret key word, finish with RETURN. (Note that it will not appear on the screen.)

You have six seconds to take down the message.


100 REM Program P67 - Encoder 110 DIM offset(25),characters(255),codes(255) 120 MODE4 130 PRINT '''"This program can be used to produce a" 140 PRINT "coded version of a secret message." 150 PRINT "The program bases the encoding on a key" 160 PRINT "word which you specify." 170 PRINT '"Neither the key word nor the message is" 180 PRINT "seen on the screen." 190 PRINT '"What is your message?" 200 VDU 21 210 INPUT LINE message$ 220 VDU 6 230 PRINT "What is the key word?" 240 VDU 21 250 INPUT key_word$ 260 VDU 6 270 280 290 FOR I=1 TO LEN(key_word$) 300 offset(I)=ASC(MID$(key_word$,I,1))-32 310 NEXT I 320 330 FOR I=1 TO LEN(message$) 340 characters(I)=ASC(MID$(message$,I,1))-32 350 NEXT I 360 370 REM encode 380 code$="" 390 J=0 400 410 420 FOR I=1 TO LEN(message$) 430 codes(I)=(characters(I)+offset(J+1)) MOD 93 440 code$=code$+CHR$(codes(I)+32) 450 J=(J+1) MOD LEN(key_word$) 460 NEXT I 470 480 490 PRINT "Your coded message is" 500 PRINT code$ 510 PRINT ''"Press any key to finish" 520 A$=INKEY$(600) 530 CLS 540 END


P68 Decoder


This program decodes secret messages created by program P67. You need to have the secret message plus the key word to find the original message.

COMMANDS

Key in program and type RUN.
Type in coded message.
Type in key word.
You have six seconds to take down message.

EXAMPLE

Coded messageRTTV
Key word12
MessageABCD


100 REM Program P68 - Decoder 110 DIM offset(25),characters(255),codes(255) 120 MODE4 130 PRINT '''"This program can be used to produce a" 140 PRINT "decoded version of a secret message." 150 PRINT "The pogram bases the decoding on a key" 160 PRINT "word which you specify." 170 PRINT '"Neither the key word nor the message is" 180 PRINT "seen on the screen" 190 PRINT '"What is your coded message?" 200 VDU 21 210 INPUT LINE code$ 220 VDU 6 230 PRINT "What is the key word?" 240 VDU 21 250 INPUT key_word$ 260 VDU 6 270 280 290 FOR I=1 TO LEN(key_word$) 300 offset(I)=ASC(MID$(key_word$,I,1))-32 310 NEXT I 320 330 FOR I=1 TO LEN(code$) 340 characters(I)=ASC(MID$(code$,I,1))-32 350 NEXT I 360 370 REM decode 380 message$="" 390 J=0 400 410 420 FOR I=1 TO LEN(code$) 430 codes(I)=(characters(I)-offset(J+1)) MOD 93 440 IF codes(I)<0 THEN codes(I)=93+codes(I) 450 message$=message$+CHR$(codes(I)+32) 460 J=(J+1) MOD LEN(key_word$) 470 NEXT I 480 490 500 PRINT "Your decoded message is" 510 PRINT message$ 520 PRINT ''"Press any key to finish" 530 A$=INKEY$(600) 540 CLS 550 END


P69 The Game of Life


This program is a variation of the game of LIFE developed by John Conway, but I have not the classical rules for life for the purposes of this program.

The program mimics the evolution of a colony of bugs. I decided to use the following rules for determining whether a bug will live from one period to another, or whether it is to die or whether a baby bug is to be procreated. The screen shows a picture of a generation of the bug colony.
The program then has two passes over the screen.

Pass one determines whether a bug has to die or not, or whether a new bug has to be procreated. A bug dies from overcrowing if it has more than three neighbours, or from loneliness if it has less than two neighbours. If the bug has exactly two neighbours then a baby bug is generated.

Pass two removes all dead bugs from the screen and shows baby bugs attaining adulthood.

To start off the program, the initial state of the colony is described by giving the position of the bugs.

COMMAND

Key in program and type RUN.
Follow instructions

  100 REM Program P69 - The Game of Life
  110 DIM X(100),Y(100)
  120 VDU 23,224,60,126,153,255,126,90,90,153
  130 bug$=CHR$(224)
  140 VDU 23,225,0,60,126,201,255,102,60,0
  150 babybug$=CHR$(225)
  160 VDU 23,226,153,90,90,126,254,126,56,0
  170 deadbug$=CHR$(226)
  180  
  190 CLS
  200 PRINT TAB(12,12) "L I F E"
  210 X=INKEY(300):CLS
  220 REM Set up initial state
  230 I=0
  240 PRINT "Enter co-ords of bugs,(99,99 to end)"
  250 REPEAT
  260   I=I+1
  270   INPUT X(I),Y(I)
  280 UNTIL X(I)=99
  290 MODE5
  300 COLOUR 1
  310 FOR J=1 TO I-1
  320   PRINT TAB(X(J),Y(J)) bug$;
  330 NEXT J
  340  
  350  
  360  
  370 FOR I%=0 TO 24
  380   REPEAT
  390     FOR X%=0 TO 19
  400       FOR Y%=0 TO 31
  410         K%=FNchar(X%,Y%)
  420         IF K%=224 OR K%=225 OR K%=128 OR K%=129 THEN P
ROCpoint_flag(X%,Y%)
  430       NEXT Y%
  440     NEXT X%
  450     REM Pass two
  460     FOR X%=0 TO 19
  470       FOR Y%=0 TO 31
  480         PROCchangestate(X%,Y%)
  490       NEXT Y%
  500     NEXT X%
  510   UNTIL 0
  520    
  530   DEF PROCpoint_flag(X,Y)
  540   LOCAL K%,neighbours%
  550   FOR I=-1 TO 1
  560     FOR J=-1 TO 1
  570       K%=FNchar(X+I,Y+J)
  580       IF K%=224 OR K%=225 OR K%=128 OR K%=129 THEN nei
ghbours%=neighbours%+1
  590     NEXT J
  600   NEXT I
  610   COLOUR 2
  620   IF neighbours%>3 OR neighbours%<2 THEN PRINT TAB(X,Y
) deadbug$
  630   IF neighbours%=2 THEN PROCbaby(X,Y)
  640   ENDPROC
  650    
  660   DEF PROCbaby(X,Y)
  670   FOR I=-1 TO 1
  680     FOR J=-1 TO 1
  690       COLOUR 3
  700       IF FNchar(X+I,Y+J)=32 THEN PRINT TAB(X+I,Y+J) ba
bybug$:I=1:J=1
  710     NEXT J
  720   NEXT I
  730   ENDPROC
  740    
  750   DEF PROCchangestate(X,Y)
  760   COLOUR 0
  770   L%=FNchar(X,Y)
  780   IF L%=226 OR L%=130 THEN PRINT TAB(X,Y) " "
  790   COLOUR 1
  800   IF L%=225 OR L%=129 PRINT TAB(X,Y) bug$
  810   ENDPROC
  820    
  830    
  840   DEF FNchar(u,v)
  850   VDU31,u,v
  860   A%=135
  870   =(USR(&FFF4) AND &FF00)/&100


P70 Biorhythms


It has been said that a human being has predictable ups and downs. The proponents of biorhythms state that there are three main cycles in life - the Physical, Emotional and Intellectual.

This program is used to show the biorhythms for any particular person at any point in his life. The program displays the three biorhythms for a period of twenty days starting from the date of interest.

The program can be used to display the biorhythms for any person in history. Note that dates must be in the Gregorian calendar.

COMMANDS

Key in program and type RUN.
Follow instructions.
Interpret biorhythm.


  100 REM Program P70 - Biorhythms
  110 MODE 6
  120 @%=9
  130 PRINT TAB(12,12) "BIORHYTHMS"
  140 X=INKEY(200)
  150 CLS
  160 PRINT "Enter date of interest"
  170 INPUT "Day (1-31) " day
  180 INPUT "Month (1-12) " month
  190 INPUT "Year (eg 1982) " year
  200 INPUT '''"Enter date of birth of subject"
  210 INPUT "Day (1-31) " b_day
  220 INPUT "Month (1-12) " b_month
  230 INPUT "Year (eg 1982) " b_year
  240 days_alive=FN_days(day,month,year) - FN_days(b_day,b_m
onth,b_year)
  250 PRINT ''"The subject has lived for "days_alive" days"
  260 PRINT '''"Press key to continue":x=GET
  270 MODE 5
  280 VDU 19,0,5;0;
  290 MOVE 0,512
  300 GCOL 0,2
  310 DRAW 1279,512
  320 FOR X=0 TO 1280 STEP 64
  330   MOVE X,500
  340   DRAW X,524
  350 NEXT X
  360 COLOUR 1
  370 PRINT TAB(0,1)"Physical ";
  380 PROCplot(23,1)
  390 COLOUR 2
  400 PRINT "Emotional  ";
  410 PROCplot(28,2)
  420 COLOUR 3
  430 PRINT "Intellectual"
  440 VDU 5
  450 PROCplot(33,3)
  460 END
  470 DEF PRCplot(p,c)
  480 MOVE 0,512
  490 GCOL 0,c
  500 FOR X=0 TO 1279 STEP 8
  510   Y=INT(400*SIN(2*PI*(days_alive + X/64)/p)+512)
  520   PLOT 5,X,Y
  530 NEXT X
  540 ENDPROC
  550 DEF FN_days(d,m,y)
  560 RESTORE
  570 FOR I=1 TO m
  580   READ days_this_year
  590 NEXT I
  600 DATA 0,31,59,90,120,151,181,212,243,273,304,334
  610 days_this_year=days_this_year+d
  620 days_since_0=days_this_year + y*365 + INT(y/4) +1 - IN
T(y/100) + INT(y/400)
  630 IF (y MOD 4)=0 AND (m<3) THEN days_since_0=days_since_
0 - 1
  640 =days_since_0

<


P71 Dog Race


This program shows a series of dogs racing across the TV screen. It can be profitable to play the part of a turf accountant while running the program.

COMMANDS

Key in program and type RUN.

  100 REM Program P71 - Dog Race
  110 REM Create dog shape
  120 MODE 2
  130 @%=2
  140 VDU 23,1,0;0;0;0;
  150 VDU 23,224,4,6,132,252,124,202,169,169
  160 VDU 23,225,224,224,224,224,224,224,224,224
  170 VDU 23,226,255,255,255,224,224,224,224,224
  180 DIM d(10),c(10),p(10)
  190 REM select colours for dogs
  200 FOR I=1 TO 10 : c(I)=I MOD 7 + 1:NEXT I
  210 COLOUR 9
  220 PRINT TAB(1,15);"R A C E  N I G H T!"
  230 Z=INKEY(400)
  240 CLS
  250 COLOUR 5
  260 PRINT TAB(0,4);"GOOD EVENING FOLKS!"
  270 PRINT TAB(0,6);"WELCOME TO THE "'"ELECTRON DOG TRACK!"
  280 PRINT TAB(0,10);"TONIGHT WE HAVE A"'"RACE WITH 10 DOGS
"
  290 PRINT TAB(0,28);"Press any key to"'"continue"
  300 z=GET
  310 CLS:VDU 19,0,2;0;0;0:VDU 19,2,0;0;0;0:CLS
  320 REM place the traps
  330 FOR I=1 TO 10
  340   COLOUR I MOD 7 +1
  350   PRINT TAB(0,3*I-1);I-1
  360   PRINT TAB(1,3*I-1);CHR$(225);
  370 NEXT I
  380 PRINT TAB(0,31);"Press key to start.";
  390 Z=GET
  400 PRINT TAB(0,31);"                   ";
  410 FOR I=1 TO 10
  420   COLOUR I MOD 7 +1
  430   PRINT TAB(1,3*I-1);CHR$(226);
  440   d(I)=2
  450   COLOUR c(I):PRINT TAB(d(I),3*I-1);CHR$(224);
  460 NEXT I
  470 fins=0
  480 REPEAT
  490   REPEAT
  500     p=RND(10):got=0
  510     FOR I=1 TO 10
  520       IF p=p(I) THEN got=1
  530     NEXT I
  540   UNTIL got<>1
  550   PRINT TAB(d(p),3*p-1);" ";:COLOUR c(p):PRINT TAB(d(p
)+1,3*p-1);CHR$(224)
  560   d(p)=d(p)+1
  570   IF d(p)=19 THEN p(fins+1)=p:fins=fins+1:SOUND 3,-10,
60,6
  580   IF fins=0 THEN PROCwinning ELSE PRINT TAB(0,0) "    
             ";
  590 UNTIL fins=10
  600 PRINT TAB(0,0) "PRESS KEY FOR RESULT";
  610 Z=GET:CLS
  620 PRINT '' "THE RESULTS WERE:" ''
  630 PRINT "1st DOG - ";p(1)-1
  640 PRINT '' "2nd DOG - ";p(2)-1
  650 PRINT '' "3rd DOG - ";p(3)-1
  660 PRINT ''"In order the rest"'"were :" '
  670 FOR N=4 TO 10
  680   PRINT "Dog ";p(N)-1
  690 NEXT N
  700 END
  710 DEF PROCwinning
  720 first=0
  730 FOR I=1 TO 10
  740   IF d(I) > d(first) THEN first=I
  750 NEXT I
  760 SOUND 3,-7,55+first*10,2
  770 PRINT TAB(0,0) "DOG ";first-1;" IS WINNING";
  780 ENDPROC


P72 Magic Matrix


This program is based on an interesting idea presented in Martin Gardener's book "Mathematical Puzzles and Diversions" (Bell 1964).

The program generates a matrix which is not a magic square, but which has some interesting properties.

I have found that this is an amusing party trick, even if I simply draw the matrix out on a piece of paper. The basic idea is rather simple, see if you can work it out.

COMMANDS

Key in program and type RUN.
Follow instructions.

  100 REM Program P72 - Magic Matrix
  110 MODE 6
  120 PRINT "This program produces a square array "
  130 PRINT "with the following interesting property."
  140 PRINT "You are asked to pick any number in "
  150 PRINT "the square. You indicate this by row"
  160 PRINT "and column number. The computer will "
  170 PRINT "then block out all other numbers in"
  180 PRINT "that row and column. This continues"
  190 PRINT "until only one number remains."
  200 PRINT ''"Notice that the sum of the numbers"
  210 PRINT "remaining is the same as that at the"
  220 PRINT "bottom of the screen."
  230 PRINT "Press any key to continue."
  240 Z=GET
  250 CLS
  260 DIM X(5,2)
  270 FOR I=1 TO 5
  280   X(I,1)=RND(30)
  290   X(I,2)=RND(30) 
  300   SUM=SUM+X(I,2)+X(I,1)
  310 NEXT I
  320 DIM A(5,5), ROW(5), COLUMN(5)
  330 @%=3
  340 PRINT ''''
  350 FOR I=1 TO 5
  360   FOR J=1 TO 5
  370     A(I,J)=X(I,2)+X(J,1)
  380     PRINT A(I,J);
  390   NEXT J
  400   PRINT
  410 NEXT I
  420  
  430 s$=""
  440 FOR J=1 TO 5
  450   PRINT TAB(0,20)"SUM ="SUM
  460   INPUT TAB(0,15)"ROW=",R
  470   INPUT TAB(0,16)"COLUMN=",C
  480   IF ROW(R)>0 OR COLUMN(C)>0 THEN 460
  490   ROW(R)=1: COLUMN(C)=1
  500   FOR I=0 TO 4
  510     PRINT TAB(I*3,4+R)" . "
  520     PRINT TAB(3*(C-1),5+I)" . "
  530   NEXT I
  540   PRINT TAB(20,4+R) A(R,C)
  550   s$=s$+"+"+STR$(A(R,C))
  560 NEXT J
  570 PRINT TAB(4,21)"="MID$(s$,2)


P73 Dice


A gambler's delight, this program rolls three dice. At the moment the dice are fair, but it is possible to seed the random number generator to make sure that the sequence of random numbers is predictable.

To do this enter the following line,

   115 X=RND(-5)

then experiment with the results.

COMMANDS

Key in program and type RUN.
Press any key to throw dice.

  100 REM Program P73 - Dice
  110 MODE 6
  120 @%=3
  130 PRINT "This program rolls 3 dice. Note no"
  140 PRINT "graphics. Press any key to throw the"
  150 PRINT "dice."
  160 Z=GET
  170 MODE 2
  180 REPEAT
  190   D1=RND(6):D2=RND(6):D3=RND(6)
  200   PRINT TAB(0,12) SPC(3),D1,D2,D3
  210   PRINT '''"Press any key for another throw"
  220   Z=GET
  230 UNTIL 0


P74 Pools Program


This program selects random numbers to help you fill up your football pools coupon.

I've not won yet!

COMMANDS

Key in program and type RUN
Follow intructions.

  100 REM Program P74 - Pools Program
  110 DIM temp%(100)
  120 @%=3
  130 MODE 6
  140 PRINT ''''"This program will not win the pools"
  150 PRINT "for you. It does not reduce the odds in"
  160 PRINT "any way, but it does remove the"
  170 PRINT "responsibility of losing from you."
  180 PRINT "The program will present you with your"
  190 PRINT "treble chance numbers"
  200  
  210 INPUT ''"How many games on entry form",games
  220 INPUT'"How many columns are you entering",columns
  230 INPUT'"How many entries in each column",entries
  240  
  250 CLS
  260 FOR I=1 TO columns
  270   FOR J=1 TO entries
  280     temp%(J)=RND(games)
  290     flag=0
  300     FOR K=0 TO J-1
  310       IF temp%(K)=temp%(J) THEN J=J-1:flag=1
  320     NEXT K
  330     IF flag=0 THEN PRINT TAB(I*5,J)temp%(J)
  340   NEXT J
  350 NEXT I
  360 REM end of program


P75 Shuffle


It is important to be able to shuffle a deck of cards if you wish to write a card game program. There are three useful routines presented in this program.

1. A routine to set up a pack of cards (lines 120-290).
2. A shuffle routine (lines 310-370).
3. A routine to deal the cards (lines 380-470).

COMMANDS

Key in program and type RUN.

  100 REM Program P75 - Shuffle
  110 MODE 5
  120 VDU 23,224,54,127,127,127,62,28,8,0
  130 VDU 23,225,8,28,28,107,127,107,8,28
  140 VDU 23,226,8,28,62,127,62,28,8,0
  150 VDU 23,227,8,28,62,127,127,127,28,62
  160 h$=CHR$(224)
  170 c$=CHR$(225)
  180 d$=CHR$(226)
  190 s$=CHR$(227)
  200 pack$=STRING$(104," "):pack$=""
  210 heart$=STRING$(26," "):heart$=""
  220 club$=STRING$(26," "):club$=""
  230 diamond$=STRING$(26," "):diamond$=""
  240 spade$=STRING$(26," "):spade$=""
  250 hand1$=STRING$(26," "):hand1$=""
  260 hand2$=STRING$(26," "):hand2$=""
  270 hand3$=STRING$(26," "):hand3$=""
  280 hand4$=STRING$(26," "):hand4$=""
  290 heart$=FNsetup(heart$,h$)
  300 club$=FNsetup(club$,c$)
  310 diamond$=FNsetup(diamond$,d$)
  320 spade$=FNsetup(spade$,s$)
  330 pack$=heart$+club$+diamond$+spade$
  340 PRINT TAB(5,1) "SHUFFLING"
  350 shuffled$=pack$:shuffled$=""
  360 FOR I=1 TO 50
  370   P=RND(53-I)*2-1
  380   shuffled$=shuffled$+ MID$(pack$,P,2)
  390   pack$=LEFT$(pack$,P-1)+MID$(pack$,P+2)
  400 NEXT I
  410 shuffled$=shuffled$ + pack$
  420 FOR I=1 TO 13
  430   hand1$=hand1$+LEFT$(shuffled$,2)
  440   shuffled$=MID$(shuffled$,3)
  450   hand2$=hand2$+LEFT$(shuffled$,2)
  460   shuffled$=MID$(shuffled$,3)
  470   hand3$=hand3$+LEFT$(shuffled$,2)
  480   shuffled$=MID$(shuffled$,3)
  490   hand4$=hand4$+LEFT$(shuffled$,2)
  500   shuffled$=MID$(shuffled$,3)
  510 NEXT I
  520 DIM X(4)
  530 CLS
  540 VDU 19,0,2;0;19,3,0;0;
  550 PROCdeal(hand1$,3,0)
  560 PROCdeal(hand2$,0,8)
  570 PROCdeal(hand3$,8,16)
  580 PROCdeal(hand4$,3,24)
  590 END
  600  
  610 DEF FNsetup(suit$,s$)
  620 FOR I=2 TO 9
  630   suit$=suit$+STR$(I)+s$
  640 NEXT I
  650 suit$="A"+s$+suit$+"T"+s$+"J"+s$+"Q"+s$+"K"+s$
  660 =suit$
  670  
  680 DEF PROCdeal(hand$,X,R)
  690 X(1)=X:X(2)=X:X(3)=X:X(4)=X
  700 FOR I=1 TO 13
  710   card$=MID$(hand$,I*2-1,2)
  720   IF RIGHT$(card$,1)=h$ OR RIGHT$(card$,1)=d$ THEN COL
OUR 1 ELSE COLOUR 3
  730   Y=ASC(RIGHT$(card$,1))-223
  740   PRINT TAB(X(Y),Y+R)card$;
  750   X(Y)=X(Y)+2
  760 NEXT I
  770 ENDPROC