Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Shortest useful program
#1
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.
Reply
#2
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.
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
#3
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
*****
Reply
#4
That can be done in only one line:

Code:
a$ = input$(1)
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
#5
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).
Reply
#6
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 ":".
B 4 EVER
Reply
#7
Yeah. QB sees colons as line breaks and nothing more. It's not a very good loophole to allow...
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
#8
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")
Reply
#9
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
B 4 EVER
Reply
#10
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 :)
url=http://www.spreadfirefox.com/?q=affiliates&id=60131&t=79][Image: safer.gif][/url]
END OF LINE.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)