Case for puzzles for programmers
I REALLY must congratulate you and Mike Bibby for the excellent
series "Introduction to Programming".
I find the clear, step by step instructions are just right for
a novice like myself to understand.
While I doubt I will ever become an expert programmer you have
no idea how much pleasure I get when I have successfully solved
one of the problems posed at the end of each article.
I am sure other readers must feel the same and I am prompted
to ask whether you could include a page (or half a page) of programming
puzzles in future issues of The Micro User.
Perhaps, if the questions ranged from very easy to very hard,
it would cater for all levels of programming abilities. - D.
Marchington, Guiseley, Leeds.
• Thanks a lot for the praise. Your idea of a regular page of
programming puzzles is a great suggestion.
There must be lots of computer teachers who have their own pet
puzzles and exercises.
So how about it? Why not send in the programs you've used to
illustrate your lessons with - then we can share them with everyone?
Incidentally, send the answers too. The editorial staff of The
Micro User are not as young as they used to be.
Clock interrupt
REGARDING Michael Pas-tore's letter in the February 1984 issue
of The Micro User, there is a way of programming one of the BBC's
internal clocks to produce an interrupt — the interval timer.
Using an OSWORD call with A=4 you can set the timer to a value
(see page 460 of the User Guide). It will then increment every
hundredth of a second and will cause an event (if you make it)
when it gets round to O.
This event indirects through &220 and so by changing the
address there, inserting a small routine at the new address and
typing *FX14,5 (to enable this particular event) you have created
a kind of alarm. The enclosed program does just that.
10-30 Sets the address for the routine to &ADE (top of the
space reserved for function keys).
40-80 Saves registers, prints CHR$(7) a number of times, recovers
registers and ends.
90-150 Sets the number to be written to the interval timer.
160 Sets registers for Osword with A=4, and pointer to &70.
170 Enables the event and sets interval timer.
This program will produce a long beep after the set number of
minutes and will work as long as all the function keys aren't
programmed - keep to two or three to be safe.
To expand the message it will be necessary to rewrite the routine
at &ADE, remembering to change the values at &200, &201
and P%.
Once you have run the program it is possible to run another
one, but do not press Break as this resets the vector and timer.
The program has been tested with delays up to 10 minutes. -
Joe Faith (14), Bletchingdon, Oxfordshire.
Lising will not OCR (Please request scan if interested)
Elegance a side effect
JUST for the record, I have never advocated recursion. Nor is
elegance the most important characteristic of good programming
in my scheme of priorities.
Frank Hughes is demolishing arguments I have never put forward.
My only original uses of recursion have been for fun or demonstation,
and elegance is a side-effect of good programming as it often
is of any kind of good design process.
I must repeat that readability is what counts most. Many good
things flow from this -correctness, shorter development time,
ease of updating or adapting, better personal skill development.
Again, for the record, I agree with Dr Freshwater that there
is no real difference between THEN GOTO 50 and THEN 50 and I have
never said there is.
They are equally undesirable and the well-documented causes
of unreadability of programs. Why is it pompous and pedantic to
say that?
Perhaps I'm not as clever as Messrs. Hughes and Freshwater.
In the old unstructured days I of ten failed to understand my
students' programs (so did they).
Now their programs are much longer and more ambitious, yet I
find them easy to understand. - Roy Atherton, Director, Bul-mershe
Computer Education Centre, Earley, Reading.
Six of the best?
DAVID H. Wilde's letter in the March "Micromail" in
reply to my own in December's would be a good endorsement for
nominating me as editor of The Wally's Guide to Home Computing.
I feel he must be a schoolmaster, determined to give me six
of the best for frivolity.
My letter was written in irritation at the smugness and preciousness
that so many programmers evince, proudly drawing attention to
the fact that "the program is fully structured, as there
is not a single GOTO or GOSUB to be found".
I cannot see why the mere omission of line directions necessarily
makes for better structured programs.
As a case in point, I recently copied out a Logo program written
by Fintan Culwin in the January 1983 "Your Computer"
and counted 36 GOTOs and 49 GOSUBs among the PROCs and functions.
Yet it was clear and structured, using all the facilities of
the language to produce an efficient and well-running program.
Can you picture the editor of Your Computer saying: "Hey
Fintan! For God's sake man, all those GOSUBs!".
Fintan goes away muttering, returns hours later with sore fingers
and the thing completely procedured. "That's better, my boy!"
beams the Ed, "and it still works just the same".
Hence I fancy the pragmatist's approach rather than the purist's.
GOTOs and GOSUBs were not just thrown in for Watties who don't
know any better. - David Bye, Saffron Walden, Essex.
GOTO h...!
I AM sick and tired of reading about PROC and GOTO. - A.N.
Haslvem, Lewisham, London.
Enhanced Blackjack
BLACKJACK, which was featured in the November issue of The Micro
User, is an excellent and well thought out game that is written
well, in spite of its cumbersome upper and lower case variable
names. However I have one small criticism relating to the way
in which bets are placed.
It is usual in Blackjack (or Pontoon even) to place your bet
on the value of the first card dealt to each player, and not to
bet blind, as in this game. I believe it enhances the game to
carry out a simple modification in PROCmain to achieve this, as
follows:
590 PROCline(" ",30,0):FOR I%=1 TO 2:PROCdeal:NEXT
I%
595 I%=6:PROCcard(130,100):PROCpause(175):PROCstake
600 FOR I%=3 TO 6:PROCdeal:NEXT I%
Line 590 now causes a faced card to be dealt to each player
and the new line 595 causes a face-down card to be dealt to the
bank. This card does not need a stored value at this stage, as
this is purely for pictorial effect to complete the first round
of the deal.
PROCstake then operates as normal, but the players can see what
they are betting on.
Line 600 then causes the bank's first card to be revealed and
the second card dealt to each player and the bank normally.
I have our version permanently amended in this manner.
One final note worth mentioning is that blue often does not
show up very well as text or narrow lines on a TV set. Try cyan
instead. It gives better relief to the black and red suit symbols.
There's a wrong note, 5 from the end, of the "Fiddler on
the Roof theme. Can anybody say what is better than pitch 141
(A sharp) for this melody? I have no ear for music, but this one
stands out! - Brian Spencer, Hertford.
Laserbug query 1
COULD you please let me know if the User Group known as Laserbug
have ceased trading?
As an independent publi-cat.ion with no advertising revenues
from them you are an unbiased judge.
On December 20, Laserbug cashed my cheque for a year's subscription.
Now five letters later, two of which were recorded, I have had
no reply. Is it possible for you to chase them up? I can get no
direct communication because no telephone number is listed. -
M.A. Parker, Haverhill, Suffolk.
Laserbug query 2
I READ with interest the letter from K.R. Derbyshire in the
April Micro User. I agree with everything he had to say.
I also found Laserbug reluctant to answer any letters if they
were of the complaint variety.
They advertise for new members every month in several magazines
but they cannot supply their existing members with the monthly
news magazines for which members have already paid for.
With regard to the certificate which Paul Barber refers to,
I don't think you will be missing out on anything worth having.
What good is a certificate from a company or user group if they
no longer exist?
I am not pushing for BeeBug, but I have found them to be very
good and very helpful in everyway and I find their magazine very
well laid out and I look forward to it every month eagerly (as
I do yours).
I would like an article in your magazine on how to formulate
a program for joysticks. I seem to find it beyond me.
Thanks for an excellent magazine, it seems to cater for the
thick like myself, as well as the pro. - K. Lavvler, Dewsbury,
Yorkshire.
• We have already covered the addition of joysticks to programs
in our Body Building course in the May, 1983, Micro User.
A utility to adapt keyboard programs was given in the October
issue. And a simple games paddle was described in our very first
issue in March, 1983.
However we have plans for a far more comprehensive article on
the subject in the near future.
Laserbug query 3
K.R. Derbyshire's experience with Laserbug comes as no surprise
to me.
On August 19, 1983,1 posted a cheque to Laserbug together with
an order for a 1.2 OS ROM. This cheque was paid by my bank on
September 6.
After a wait of some six weeks there was no sign of the ROM.
During the next six weeks a number of letters, including one from
the Trading Standards Office, Eastbourne, were all ignored.
One of these letters might have gone astray, but not all, and
certainly not the last, which was Recorded Delivery.
As seven months has elapsed it is clear that Laserbug intend
to keep my money. Subsequently I obtained the ROM elsewhere with
no trouble at all.
I would cheerfully have obtained a county court summons to reclaim
the money. However I was advised that it\ was necessary to ascertain
the name of the owner of the concern.
Since the Register of Business names has now been abolished
the only way to obtain this information was by a request to Laserbug.
My advice to anyone dealing with Laserbug is "caveat emptor!"
- T.W. Clements, Hailsham, Sussex.
Watch out for stolen equipment
I AM sure I am not the only BBC computer user whose addictive
hobby has been interrupted by burglary and theft, and it occurs
to me that you could perform a useful service by publishing a
list of stolen equipment, with serial numbers.
This could set honest dealers and users on their guard when offered
second-hand equipment, and possibly lead to the conviction of
thieves and others handling stolen property.
My experience is a warning to other computer users, as only
micro related equipment was stolen. I have to ask myself whether
I have talked about my Beeb, printer and Prestel adapter to any
strangers who could have taken a fancy to it.
I do not wish to run the risk of my replacement equipment being
stolen, so l ask you not to publish my name and address. A list
of the items stolen from my home on March 7 is as follows:
BBC model B computer, 1.2 OS, serial number 105521; Shinwa CP80
printer, with cable (5002853), Ferguson TX colour television,
grey cabinet, model 37140, 14in. (G104205), Sony TCS300 portable
cassette recorder with rechargeable batteries (98274), Tandata
TD1100 Prestel adapter (29135).
Keep up the good work in the magazine. For one who was contemplating
disc drives, the March edition I found particularly useful. -
Name and address supplied.
• Sorry to hear about the loss of your equipment. We're only
too glad to publish the list of missing items and we'll endeavour
to do the same for other readers.
If anyone out there recognises any of the items, let us know.
Prime numbers check-up
THE program "Finding Prime Numbers" was written in
response to a request from some of my secondary modern arithmetic
pupils to have a readily available check on which numbers are
prime.
Finding the first few is relatively simple to do manually, but
as the upper limit increases the exercise becomes tedious and
time consuming.
The program, therefore, also calculates the time taken to find
the numbers.
As written, the program will print out the results in eight
columns up to the desired limit, the display on the screen being
in four columns.
If the program is to be run without a printer line 120 must
be deleted - VDU2 being the command that will "activate"
the printer, in my case an Epson MX-80.
It would also be prudent to delete line 290, which switches
off the printer.
The variables used are:
PN The number being tested for "primeness".
Y A count, used to control the tabulation on printout.
FLAG This is set to 0 until PN is found to be non-prime when
it is then set to -1.
- C.H. Hayter, Gillingham, Kent.
10 REM FINDING PRIME NUMBERS
20 REM
30 REM (C) C.H.Hayter
40 REM
50 REM 1983
60 REM
70 REM This program will list the primes on a printer
80 REM If you are not linked with a printer it will be necessary
to delete lines 120 and 290
90 MODE 7
100 INPUT TAB(5,10)"UP TO WHAT LIMIT ? "NUM
110 CLS
130 TIME=0
140 PRINT"LIST OF PRIME NUMBERS UP TO ";NUM
150 PRINT"******************************"
160 PRINT
170 PN=0:Y=0
180 REPEAT
190 PN=PN+1:FLAG=0
200 FOR X=2 to INT (PN/2+.5)
210 IF PN/X=INT (PN/X) THEN FLAG=-1
220 NEXT X
230 IF PN=1 FLAG=-1
240 IF PN=2 FLAG=0
250 IF FLAG=0 PRINT TAB(Y*10);PN;:Y=(Y+1) MOD 8
260 UNTIL PN=NUM
270 PRINT'''"Time taken ";TIME /100;" seconds."
280 PRINT ''''
No problem
AS a fairly new BBC B owner am I alone in viewing with slight
alarm the appearance of the Electron ?
I am worried that software houses will now tailor existing programs
and write new programs predominately for the Electron's reduced
capabilities with the tag line that they also work on the BBC.
Could we BBC users end up with inferior programs, which for
sound commercial reasons will be aimed at the combined Electron/BBC
market? I hope not.
I wonder if any program house could allay my fears. - M.J.
Morris, Cheltenham.
• Quite frankly, no programming house would be so stupid. They're
in it for the money, and BBC Micro owners are a discriminating
lot.
You identified
I FELT I had to write to you, as I have one or two unanswered
questions, as well as the odd comment.
Firstly, though, may I add my name to those thousands in praising
the high quality of the articles and the way in which they are
presented - not assuming we know it all.
Now to the questions:
While playing around with my machine operating calls, I came
across the OSFILE routine which deals with files, accessing an
78 byte control block stored in memory, the last four bytes of
which give the file attributes.
The LSB of these four, states the User Guide, can be assigned
a value of 0-7, which include "not readable by you,"
"not executable by others," etc.
Could you please tell me how you tell the computer who "you"
and "others" are for future use of the file?
Also, has anyone found a use for the Tab key, except for dropping
smart bombs? - Stuart Reynolds, Thorpe Bay, Essex.
• "You" means the user reading the attributes and "others"
means other users of, say, the Econet filing system.
The Tab key was included in the BBC Micro for use with word
processors. As you know, its Ascii value may be changed by using
the command *FX219 (OSBYTE&DB).
Auto run to music
AFTER typing in the Christmas Card program listed in The Micro
User for December 1983, I found that by adding the lines:
935 TT%=TIME
1015 IF TIME >TT%+9100 THEN RUN
the program auto ran itself after the candles had been on the
tree while Silent Night played. - Andrew Baker, Wellfield Junior
School, Sale, Cheshire.
Control code catch
CONTRAR Y to your comment on Michael Swatton's letter (Micromail,
February 1984), control codes are not suppressed when sending
output to "printer only" under *FX3,10.
The catch is that under *FX3,10, code 1, normally used in print
statements to prevent control codes reaching the screen and removed
from output by the computer, is sent along with everything else
to the printer.
For example, a two byte control sequence such as ESC+X (which
turns on underlining in my NEC printer) is normally coded as VDU
1,27,1,88 and received by the printer as 27,88.
Under *FX3,10 the printer receives the full sequence 1,27,1,88.
Note that the byte immediately following code 27 is now 1, not
88.
The sequence 1,27,1 means nothing to the printer, so it ignores
it, treats 88 as a printing character and prints "X".
My solution has been to omit the VDU1s from print statements
that are to be executed under *FX3,10.
Alternatively, if *FX6 is not required to suppress linefeeds
or some other character, *FX6,1 will ensure that code 1 does not
reach the printer, even under *FX3,10. - Colin W. Robertson,
Maidenhead, Berks.
Remember the Tyros
AS a regular reader from your very first edition, may I make
a plea for people like myself who have no proper training in computers.
Please keep a fair proportion of your magazine for those who
still think that "&" means "and".
The articles and letters I find most interesting are those which
are quite simple but can be of considerable help when attempting
to write a program.
The two listings I enclose are examples of what I mean. Perhaps
you will see fit to publish them. I find them very useful for
headings, etc. - P. A. Back, Bournemouth.
10 REM "CENTRE"
20 MODE 7
30 PROCCENTRE("CENTRED",8)
40 PROCCENTRE("HEADINGS WITH",12)
50 PROCCENTRE("COLOUR",16)
60 END
70 DEF PROCCENTRE(A$,Y)
80 PRINT TAB(20-LEN (A$)/2-2,Y)CHR$ 141;CHR$ 129;A$
90 PRINT TAB(20-LEN (A$)/2-2,Y+1)CHRS 141;
100 ENDPROC
110 COLOUR C%
120 PRINT TAB(10-LEN (A$)/2,Y)A$
130 ENDPROC
10 REM "CENTRE"
20 MODE 2
30 C%=1
40 PROCCENTRE("CENTRED",8)
50 C%=2
60 PROCCENTRE("HEADINGS WITH",12)
70 C%=3
80 PROCCENTRE("COLOUR",16)
90 END
100 DEF PROCCENTRE(A$,Y)
110 COLOUR C%
120 PRINT TAB(10-LEN (A$)/2,Y)A$
130 ENDPROC
Over the barrel
I REFER to your program listing of "Barrel Battle"
in the January 1984 Micro User.
The problem I have is on lines 82, 87 and 89.
These require more than six lines of space when typing them,
which of course the BBC B will not accept.
What can be done about this? I always read your magazine and
would appreciate your help. - T.W. Hayter, Orpington, Kent.
• Sorry you're having problems. The answer is quite straight
forward, though.
The insert on the first page of the listing tells you that it
is a special formatter and not to press Return until you get onto
the next line.
So, where the listing reads:
31 X%=X%+H% (spaces)
:Y%=Y%+V% (spaces)
:COLOUR Q%
:C%=C%+1
:IF C%=229
etc
you type:
31 X%=X%+H%:Y%=Y%+V%:COLOUR Q%:C%=C%+1:IF C%=229
and so on until the end of the line.
Tutorial
THANK you for your series of articles in The Micro User under
the heading "Tutorial" - that is, up to part six.
But what happened in the September 1983 issue, and since?
I subscribe to your magazine exclusively for this series because
of its superiority over the BBC User Guide which, and I quote,
"is NOT a step by step course in basic programming".
- C.T. Hodgson, Malvern, Worcs.
• Thank you for your kind comments. The article did not appear
in the September issue, but it has been in every month since.
In October it was called "Loops" in the contents page,
and from then on it has been titled the more sensible "Beginners".
* * *
WILL you please tell me where I can obtain software programs
for the BBC Model B on farm planning, budgeting and accounting?
- D.P. Gibbon, Cringleford, Norwich.
• Sorry, we've never heard of any programs aimed at farming.
And finally, with tongue firmly in cheek . . .
Hoping for a Bad Dim
Dear Trev,
Sorry I haven't written for so long but I've been trying to
get in the Guinness Book of Records for teeth gnashing (with optional
hair tearing).
The reason, of course, is Andrea or, rather, Andrea's friend
Deirdre.
Remember when I had to have my Beeb in the front room because
the bunker was being redecorated? Well Deidre called round and
saw me using Bug.
"Oh", she cried, "isn't it nice? George has got
a Sloth, but this is much better. Does it do colour?"
Well you know me, little ROM and rather a lot of output interfaces.
Of course I had to tell her all about the graphics abilities of
the Beeb. I waxed on like an Acorn spokesman, telling her everything
but the delivery date.
"Pixels!" she cried, "How sweet!" A glazed
look came to her eyes and I realised that she was hooked, another
embryo micro addict.
"You know, a program is just like a knitting pattern, only
lots more fun", she enthused.
Andrea arrived home shortly afterwards and saw what was going
on. "So he's been showing you his thing, has he? Don't let
him lure you upstairs to let you look at his listings".
Deidre (bless her) ignored this and told A. how grateful she
was that I'd showed her how to use Bug. Apparently George wouldn't
let her use his Sloth even though she'd often asked.
"Don't worry", A. said, spontaneous generosity making
her voice swell, "you can come round and use Bob's micro
anytime you want".
"Anytime you want" being the operative words. Nowadays
I can't get on my micro for Deidre popping round for "five
minutes on the Beeb" and staying until the early hours monopolising
my micro.
I just sit around thinking nostalgically about the good old
days when all I had to worry about was whether or not I'd remembered
the cassette bugs fix.
As it is I pine for a Syntax Error message or a Bad Dim. I'm
getting both withdrawal symptoms and funny looks from George.
It's got so bad that I dream about it at night. Somehow or other
I'm a resistance fighter in an occupied country during the war.
I'm wandering the streets trying to find a safe house where I
can set up my illicit Beeb.
As I'm typing away in comes Deidre (looking frighteningly fetching
in her black leather uniform) and grabs my micro.
Invariably I wake up screaming, "Not again, Deidre",
which gets me funny looks from Andrea as well.
Yesterday I found myself playing with my pocket calculator for
comfort. I think I'm cracking up. Any advice?
Bob
P.S. All is well, Deidre's bought her own micro. Apparently
she got the money by selling a program she'd written. You draw
a picture of a pullover on the screen and the Beeb prints out
a knitting pattern. And as a reward for "lending" her
my micro, she's knitted me a special pully with every error message
on it. People can be so thoughtful!