Re: 20 Line Programming Challenge
Posted: Tue Jul 12, 2011 3:19 pm
Just to stay one step ahead of Mr Navigator
here's another effort. This is a Guess The Animal game where you have to think of an animal and the computer tries to guess it. As it fails to guess the answer it asks more questions to help it distinguish between the various animals, e.g. does it go moo would have na answer of y for yes for a cow but no for a pig. The longer you play it, the bigger the database becomes and the better it becomes at guessing everything. If the facility to save the database was added (aw, come on, i'm only allowed 20 lines!) it would rapidly build up a good knowledge of the animal world. Trivial as it stands, I guess it could be taught to ask medical questions to become an expert at diagnosing illnesses by asking all sorts of Yes/No questions. It's adapted from a much longer program I wrote back in 1985 IIRC


Code: Select all
100 REMark Guess The Animal: think of an animal,computer guesses it
110 CLS : CLS #0 : DIM question$(50,56),p(50,2) : free = 2
120 question$(1)='a monster' : num=1 : REMark start from somewhere,I suppose
130 PRINT'Think of an animal, computer will try to guess it and learn from replies.'\\
140 REPeat ask
150 IF p(num,1) = 0 THEN
160 PRINT'Is it ';question$(num);'?'
170 IF INKEY$(-1)=='y' THEN
180 PRINT'I knew that!'\\'Think of an animal' : REMark a correct guess
190 ELSE
200 question$(free) = question$(num) : INPUT'What was it?';question$(free+1)
210 INPUT'Enter a question to distinguish between them:';question$(num)
220 PRINT'What is the answer for ';question$(free+1);'?'
230 IF INKEY$(-1) == 'y' THEN p(num,1) = free + 1 : p(num,2) = free:ELSE p(num,1) = free : p(num,2) = free+1
240 free = free + 2 : PRINT'A new one!'\\'Think of an animal'
250 END IF : num = 1
260 ELSE
270 PRINT question$(num);'?' : IF INKEY$(-1) == 'y' THEN num = p(num,1) : ELSE num = p(num,2)
280 END IF
290 END REPeat ask