Collaborative critical study of one-line BASIC program written for the Commodore 64


36 Responses to “Collaborative critical study of one-line BASIC program written for the Commodore 64”

  1. Jacob Ewing says:

    I have many fond childhood memories of programming on the Commodore VIC-20 that my dad gave me (it was a hand-me-down when he upgraded to the C64).  That was a major part of my childhood.  Now it’s my career (albeit on somewhat faster machines).

  2. semiotix says:

    Innnnnnnnteresting. The late lamented Beagle Bros. used to publish one-line programs for Applesoft BASIC on their catalogs and invoices. Like this one they had weird emergent effects; unlike this one they often exploited obscure and deeply weird quirks in the Apple instruction set.

    If anyone has any of those Beagle Bros. programs lying around, I’d love to know about them. There are only a few posted anywhere obvious online.

    Incidentally, if anyone is curious what THIS program does, here’s a YouTube link.

  3. Nadreck says:

    Do they get into Basic’s birthplace over on the General Electric Mainframes?  Those things were full of self-modifying code like this, mostly to save space, and that paradigm carried over into the desktop world where things were still very tight long after mainframes had memory measured in entire MegaBytes!

    • Crashproof says:

      This isn’t an example of self-modifying code, it’s just written slightly compactly.  It isn’t even aware of any previous states.  To self-modify code in BASIC on a C64 you’d be seeing POKE commands, and there’d need to be a knowledge of what the address of the code was.

  4. Matisse Enzer says:

    In perl:

    START: print chr( rand(1) <= 0.5 ? 47 : 92 ) ; goto START;

    But, you need the right font for it to be anywhere as cool as the original.

    • Guest says:

      You would need zero or near-zero interline spacing… go ask a typsetting geek for such an abomination, he might well throw a fit.

      Edit: I found it less risky to install vice – when on linux this is also helpful:

    • You beat me for conciseness.  I was going to propose this from “any” *nix shell:

      perl -e ‘while(1) { $j=int(rand(2)); $q=92; $q = 47 unless $j == 0; printf “%c”, $q ;}’

      But with your example, I’d make it:

      perl -e ‘while(1) { printf “%c”, int(rand(2)) == 0 ? 92 : 47;}’

      • Here’s a variation that assumes:
        (1) Your shell doesn’t have “noclobber” set
        (2) Your current working directory is writeable
        (3) The filesystem your current working directory is on allows execution
        (4) You have a C compiler called cc

        ( echo “#include ” ; echo “#include ” ; echo ‘int main(int argc, char *argv[]) { int i; while(1) { i = (random() % 2); printf(“%c”, i==0 ? 47 : 92 ) ; }}’ ) > /tmp/X.c && cc /tmp/X.c -o xR ; ./xR

        It’s getting ugly now.

        Anyone willing to do this in intercal?

  5. Ashley Yakeley says:

    I was confused by the semicolon – colon at first. It turns out that the
    colon is the statement separator, and the semicolon is an option to the print statement to stop it printing a newline.

  6. a) enjoyed Nick’s “Twisty Little Passages” about interactive fiction and look forward to a few afternoons with the text featured above.
    b) if one were inclined to implement the code but lacked a readily accessible version of BASIC one could go here:

  7. noah django says:

    this makes me happy and sad at the same time.  happy because it is so neat-o and because it reminds me of the fun I had with my friend Brian.  We were in the same 7th grade computer class (this is 1986/7) and on his home PC we wrote our little choose-your-own-adventure games in BASIC.  I remember our longest one was an espionage scenario and if you made the wrong choice the antagonist would say “OFF TO ZE GAS CHAMBER WITH YOU AH HAHAHAHAHAHA!” which Brian wrote (he was a jew, lol.)

    Then, before the year was over, I moved to another state with no money for education; no computer lab, no programming classes.  No money at home so no home PC.  I was homesick for my bestie.  I saved the floppies we had made for years even though I had nothing to play them on.  Now I have a Mac and it does everything for you, which I need, because I am computer retarded instead of the programmer that I wanted to be ;_;

  8. Rick. says:

    I was programming in basic on my C64C up until about ’91. That was when my beloved Commodore 64 finally died.

    I just typed this one liner into the C64 emulator on my iPhone. Awesome!

  9. MythicalMe says:

    Never had a C64, but I did have TRS-80 Color Computer. Unlike the Commodore, Microsoft wrote the BASIC interpreter. Many of us CoCo owner saw value in our “game” machines. I’d already learned BASIC from our computer lab (1972) in junior high which was connected to a DEC PDP via a telephone coupler at a speedy 75 baud rate.

    I know that Microsoft wrote the BASIC interpreter because CoCo magazine published a disassembled listing, and thus began my quest to learn 6809e assembler language (my second computer language). I know many computer languages now.

    Getting back to BASIC, knowing that the maximum length of a single line of code was 255 characters, the CoCo magazines challenged readers to write the longest, and useful, one line programs that could be programmed. Some of those programs were pretty intricate. If you knew the 6809 machine code, you’d POKE (put a value directly into memory) a machine language program and execute it. Fun times.

  10. This was also  included in the  “Introduction To Basic” instruction manual that came in the Vic-20 Starter Pack; 30 years later and I remember it was described therein as creating a “pseudo-maze”.

    With a random character set of just 2 elements, I expect there’s some mileage in discussions regarding the “pseudo” bit and randomness. The output certainly looks pretty convincing to me.

    Looking at the maps created in Diablo 1 and 2 used to bring this bit of code back to my mind.

  11. Anders Candell says:

    Try it out here:

    Remember to type “run” when you have entered the line.

  12. Cameron McCormick says:

    Why is this book only available as a hardcover? I would buy it right now if it was an ebook. I find it kind of strange to have a computer science book from MIT of all places available only on dead trees. It’s akin to releasing an electronic music album on cd only.

  13. hbgvfcdxsz hbgvfcdxsz says:

    what does the program do? print NMNMNMNMN?

  14. Gordon Stark says:

    When my dad was teaching me programming on his D116 Minicomputer in the mid-70′s, he gave me a problem to solve, and I think my program solution was about 50 lines of code to perform some character manipulation to reverse anything input.

    After I completed, and felt very accomplished, he gave me a low mark, and said that that was what was wrong with programming of the day, where coders fill memory with code when all they need is a single line, and he then wrote a complex 1 line loop  to solve the problem.

    That lesson has stuck with  me ever since.

  15. Quibbler says:

    First that is a two line programme the : separates the two lines.
    Second I think you need an INT in there
    CHR$(INT(205.5+RND(1)) you certainly do in QBasic. 

  16. For fans of glitch there’s best oneliner ever:
    7C 00 05 A2 29 3F A8 E5 A1 45 A2 05 A2 29 7F 99 00 D4 99 D7 CF 50 EB

    Sound and visual from these 23 bytes:

    • B E Pratt says:

       That is just awesome. But I gather that you would want to take precautions before trying to run this using a decent sound system. Danger on the low end of frequencies :)

  17. Doug in_PDX says:

    What a culture indeed!  I was there, using an Atari, Apple ][ and Color Computer.

    A few "photos" while we all go get this book to read:

    Discovering fixed point binary numbers on a chalkboard.  These were needed to get various smooth movements of on screen objects, eliminating lots of counters and other fluff code written to deal with integers...   Math teacher quote:  Nobody really uses binary.  When confronted with:  x = x + (y > 5), "nonsense!"  Comparison result as number, bridging logic and math into one useful thing.

    Late day or early morning floppy copy parties in the Apple lab at school.  20 + machines can move a lot of games.

     Looking forward to trips to the grocery store with mom.  Why you ask?  Was it candy?  The thought of getting to pick something great for dinner?  Of course not!  It was access to the magazine rack!  COMPUTE!  Creative Computing, BYTE, ANTIC, RAINBOW, others all were there on display filled with pictures of the future, products one can buy and most importantly, type in games, hacks and lessons on programming.  Those were right next to other magazines, like "Hot Rod" where tinkering with computers was seen in ways similar to modding your car.

    Hand assembling 6502 machine code for use on the Apple ][, which had no fancy sprites or sound.  History class seemed so surreal.  Here I was mastering hex, learning opcodes and doing so to work for hours on a short, but fast program that would likely finish before I had even become aware of pressing the "return" key to execute it, only to turn right around and do it again and again in search of that moving object or funky sound...

    Teen age girls almost uninterested until they meet LOGO.  Suddenly those cool curves and recursive geometric art just oozed cool and there they were typing stuff in just like the rest of us, oohing and ahhing over various designs.

    ...a discussion about music on a chip!  Little did we know.  At the time, the data rates required seemed fantastically bad, CD players were something a few of us were saving lunch money for, legends of sound in those magazines featuring expensive and exotic products.   The idea of no moving parts, tunes on little cards that fit in your pocket seemed almost doable...  Nobody really saw the Internet coming, nor the stellar explosion of data transfer rates and storage that was about to hit.  My first portable music player was surreal.  It could hold a few hundred tunes and was small enough to get lost easily.  Then came that smaller iPod, about the size of the little memory cards seen on "Star Trek" and I felt both a little old, because that earlier time seemed distant, and a bit young because all the new tech still makes me want to play.

    Good times everyone! 

    Edit: A nicely equipped Apple //e sits on my desk. It is still useful. Often, I will write on it, then transfer my work to a modern PC via USB thumb drive. :)

    And I strongly second finding those Beagle Bros. one liners. I absolutely would type it in to see what coolness people can pack into just 8 bits worth of bytes!

Leave a Reply