Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Shortest useful program
#11
Quote:That can be done in only one line:

Code:
a$ = input$(1)

Toonski, your one-liner works *most* of the time. However:

1) If the user keys more than 1 character, your routine will take the first character, and subsecuent characters will be left in the buffer for a later input$ or inkey$ to read. This is exactly what I don't want. If I asked the user to answer "Y" or "N", I only want to read a one character Y or N for processing. If he hits "NO", my routine would just process the "N" and ignore the "O". However, it detects the "O" and throws it away so it doesn't get read later.

2) My routine uses INKEY$ which permits the user to press extended characters like Home, PageUP, PageDn, Up, Down, Left, Right, etc. Your use of Input$ will not handle these extended characters.

In conclusion, my routine addresses a complete, general purpose solution to the stated specifications, which are"... gets one and only one character from the user, and makes sure that he didn't enter more than one by gobbling up any excess characters." These specifications don't mention reading extended characters, but the routine does not exclude them, assuming they are implicit.
*****
Reply
#12
so? then it only needs 2 lines:
Code:
10 a$ = inkey$
20 IF a$ = "" THEN GOTO 10

or if you wanted to do that silly "wait for key to be lifted" thing:

Code:
10 a$ = inkey$
20 IF inkey$ <> "" then b = 1 else b = 0
30 IF a$ = "" AND b=0 THEN GOTO 10 else if a$ <> "" and b = 1 then goto 20

but you're still using excess code. besides, if the user presses more than one key, who cares?
i]"I know what you're thinking. Did he fire six shots or only five? Well, to tell you the truth, in all this excitement, I've kinda lost track myself. But being as this is a .44 Magnum ... you've got to ask yourself one question: 'Do I feel lucky?' Well, do ya punk?"[/i] - Dirty Harry
Reply
#13
Quote:The idea of the contest is make a useful program, and with as fewer lines as possible.

If i don't permit colons its be very difficult (or impossible) to make an useful program in just tree lines.

But like was mentioned before, a colon is just a line break. Perhaps you'd like to change the challenge parameters to 6, 9 or 15 lines.
Reply
#14
Quote:... besides, if the user presses more than one key, who cares?

Toonski, who cares? The program cares. If the user hit more than 1 key, the first one gets processed and the second or more stay in the buffer. Later if you do another input$ or inkey$ you will process these left over characters. The worst part is that they my be valid for the second input$ or inkey$. In this case the user sees the prompt but never gets a chance to key anything. The program took off without him, processing the stuff in the buffer.

I'm not making this up. This is a real problem especially in a large data entry programs that have a lot of yes/no questions which, for speed, the answers are processed as ONE KEY ONLY with no Carriage Return.

I know you understand 'cause you're smart. Sometime you just like to kibitz.
*****
Reply
#15
if you use inkey$ or input$ it takes the input and adds a small delay before letting that input repeat. that's built into bios or the dos API somewhere. you'd have to hold it for a full second before it starts to repeat. but if such is a real problem, use a proper key buffer to input from key releases. then you can really use special keys like alt and ctrl.
i]"I know what you're thinking. Did he fire six shots or only five? Well, to tell you the truth, in all this excitement, I've kinda lost track myself. But being as this is a .44 Magnum ... you've got to ask yourself one question: 'Do I feel lucky?' Well, do ya punk?"[/i] - Dirty Harry
Reply
#16
I'm thinking that the best i can do now is to drop this contest.

Make other later, given more explicit rules.

Sorry for the troubles i may cause.
Reply
#17
not quite true, toonski.. colons function much differently then line breaks when there's an if around, and sometimes you can't even use them....
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#18
TOONSKI,
I give up with you on this issue. You're being stubborn and just don't want to see my point.
*****
Reply
#19
Quote:I'm thinking that the best i can do now is to drop this contest.

Make other later, given more explicit rules.

Sorry for the troubles i may cause.
XHANTT,
You didn't cause any troubles. This is a perfectly good challenge. People will differ on what is "useful" code, and this is a good thing. But, if they don't difffer on this, they will always find something to differ about. So don't worry.

I vote that we continue this challenge.
*****
Reply
#20
it would be better if the code was limited to 1024 chars or something like that and not lines
'd like to change the world - but God doesn't give me the source code
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)