Qbasicnews.com

Full Version: Shortest useful program
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5
A few years ago, i read an article from an programming magazine. In this article the author said that, when he was at the university, every year there was a contest. It consist in making a program in basic with just 3 lines of code (like the haiku poems)
(Note: the article made a criticism about the grow up of the size of the software).

He comment that every year the level of programing were increassing from just simple things to make an entire game (Note: this was the time of the home computer).

I was astonishing when read that article. Years later in another magazine, there was a contest "make the shortest arcade game". There were differente categories: fewest lines of code, smallest executable. And of course the game have to be amusing.

So, what is the best what you can do in just 3 lines of code. There is no other limitation.
PS. No colons or call absolute, .qlbs, "run", "chain" or "shell", loophole-mongers.

DO UNTIL INKEY$
PRINT TIME$
LOOP

well, i'm shot. i hope there's a more useful program out there in 3 lines.
Toonski's use of INKEY$ gave me an idea.
Hope you allow this, it's actually more than 3 lines.
This is a routine (which can be the guts of a SUB) which 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.
Code:
DO
      TheKey$=INKEY$
    LOOP WHILE TheKey$=""
    WHILE INKEY$<>"":WEND
*****
That can be done in only one line:

Code:
a$ = input$(1)
When i say 3 lines of code, i mean "everything" you can do in a line (ie use of colons), but other things like "chain" don't count (like the use of external library).

"All" your program do must be done in tree lines.

The following plot the "tan" function:

Code:
SCREEN 12: WINDOW (-3.14, 1.5)-(3.14, -1.5)
FOR x = -3.14 TO 3.14 STEP .01: PSET (x, SIN(x) / COS(x)): NEXT x
LINE (-3.14, 0)-(3.14, 0): LINE (0, 1.5)-(0, -1.5)

Sureley this isn't much usefull, but may be (if you are studing maths).
Quote:
Code:
SCREEN 12: WINDOW (-3.14, 1.5)-(3.14, -1.5)
FOR x = -3.14 TO 3.14 STEP .01: PSET (x, SIN(x) / COS(x)): NEXT x
LINE (-3.14, 0)-(3.14, 0): LINE (0, 1.5)-(0, -1.5)

Actually this code should look like that:

Code:
SCREEN 12
WINDOW (-3.14, 1.5)-(3.14, -1.5)
FOR x = -3.14 TO 3.14 STEP .01
PSET (x, SIN(x) / COS(x))
NEXT x
LINE (-3.14, 0)-(3.14, 0)
LINE (0, 1.5)-(0, -1.5)

I think that when the competition rules say that only 3 lines of code are allowed you AREN'T allowed to put 2 lines in one by using the ":".
Yeah. QB sees colons as line breaks and nothing more. It's not a very good loophole to allow...
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 the whole idea is to make an useful program. "Good if brief the twice good thing" (o mejor en español: "lo bueno si breve dos veces bueno")
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.

Then make 9 lines out of the 3 lines and permit colons
This shows the CHR$() and ASC() values of a pressed key. Smile
Code:
10 key$ = INKEY$
20 IF LEN(key$) > 1 THEN PRINT key$, "0 +"; ASC(RIGHT$(key$, 1)) ELSE IF LEN(key$) > 0 THEN PRINT key$, ASC(key$)
30 IF key$ <> "q" THEN GOTO 10      ' "q" for quit :)
Pages: 1 2 3 4 5