Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
"5-line" engine
#9
It's a form of Code Golf, but instead of creating the smallest possible program you are packing as much functionality into the fewest lines (or one line) as possible.

@MasterGy:
It was a real eye opener when I realized that comparison operations could be used mathematically.
For instance using
y = y- (y<0) : y = y+ (y>5)
to bound y to the range of 0..5.  Much faster and more compact than IF..THENs, and more readable once you know the trick.  I was so proud of myself as I started finding ways to improve my existing programs.


Re LOC: I'll often combine two or more closely related operations on a single line, because I find it to be much more readable when I can take in more of the program on a single editor screen or printed page.  Also, grouping the code up physically helps to clarify the program logic in my mind.


A dusty old one-liner:
Model III Basic had a line length limit of 255 characters.  One trick I "discovered" was to type in as many characters as possible, hit <ENTER> and let the interpreter tokenize the line, then edit the line to add even more.

This one-line drawing program for the Model III weighs in at 220 characters, so no problem there.  Note that no target line number is given to the GOTOs.  0 was the default target if none was given.  Also, the THEN keyword was not strictly required:

   

The two POKEs make this a self-modifying program.  The SET...PEEK...RESET sequence which provides a flashing cursor in "erase" mode becomes RESET...PEEK...SET in "draw" mode.  (The PEEK reads the Model III's keyboard matrix to get the status of the arrow keys, spacebar (draw/erase toggle), and CLEAR key (clears screen).

(I later wrote a full drawing program in Basic, using every trick up my sleeve to get near machine-language speed wherever possible.  Although I once had just about every line of that program memorized, looking at it all these years later even I cannot figure out what my own program is doing at some points.  That program in dense!)
Reply


Messages In This Thread
"5-line" engine - by James D Jarvis - 02-06-2024, 02:13 PM
RE: "5-line" engine - by SMcNeill - 02-06-2024, 02:40 PM
RE: "5-line" engine - by James D Jarvis - 02-06-2024, 05:43 PM
RE: "5-line" engine - by bplus - 02-06-2024, 06:27 PM
RE: "5-line" engine - by GareBear - 02-06-2024, 10:42 PM
RE: "5-line" engine - by JRace - 02-07-2024, 01:30 AM
RE: "5-line" engine - by MasterGy - 02-07-2024, 02:31 PM
RE: "5-line" engine - by TerryRitchie - 02-07-2024, 02:46 PM
RE: "5-line" engine - by JRace - 02-07-2024, 05:25 PM
RE: "5-line" engine - by MasterGy - 02-07-2024, 08:27 PM
RE: "5-line" engine - by GareBear - 02-08-2024, 12:00 AM
RE: "5-line" engine - by SMcNeill - 02-08-2024, 12:15 AM
RE: "5-line" engine - by JRace - 02-08-2024, 03:43 AM
RE: "5-line" engine - by GareBear - 02-08-2024, 01:27 PM
RE: "5-line" engine - by SMcNeill - 02-08-2024, 05:13 PM
RE: "5-line" engine - by MasterGy - 02-08-2024, 05:22 PM
RE: "5-line" engine - by SMcNeill - 02-08-2024, 06:03 PM
RE: "5-line" engine - by SMcNeill - 02-08-2024, 07:12 PM
RE: "5-line" engine - by MasterGy - 02-08-2024, 11:01 PM
RE: "5-line" engine - by GareBear - 02-09-2024, 02:35 PM
RE: "5-line" engine - by SMcNeill - 02-09-2024, 03:23 PM
RE: "5-line" engine - by madscijr - 02-10-2024, 12:25 AM
RE: "5-line" engine - by GareBear - 02-09-2024, 05:48 PM
RE: "5-line" engine - by bplus - 02-09-2024, 08:42 PM
RE: "5-line" engine - by MasterGy - 02-09-2024, 09:24 PM
RE: "5-line" engine - by MasterGy - 02-09-2024, 09:51 PM
RE: "5-line" engine - by SMcNeill - 02-09-2024, 10:36 PM
RE: "5-line" engine - by MasterGy - 02-09-2024, 11:55 PM
RE: "5-line" engine - by bplus - 02-10-2024, 12:04 AM
RE: "5-line" engine - by MasterGy - 02-11-2024, 01:28 AM
RE: "5-line" engine - by SMcNeill - 02-11-2024, 01:35 AM
RE: "5-line" engine - by MasterGy - 02-11-2024, 04:22 PM
RE: "5-line" engine - by johannhowitzer - 02-12-2024, 02:41 AM
RE: "5-line" engine - by James D Jarvis - 02-15-2024, 06:59 PM
RE: "5-line" engine - by Pete - 02-16-2024, 10:05 AM
RE: "5-line" engine - by Jack - 02-16-2024, 11:06 AM



Users browsing this thread: 2 Guest(s)