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

Nick sez,

Remember those BASIC programs you typed into your C64? Now there's a book written about one. And the program is only 1 line. And 10 people wrote this book. As one. And they're not lunatics but teach at MIT and USC and other fancy places. And they even wrote programs to study it.

10 PRINT CHR$(205.5+RND(1)); : GOTO 10 is a book of Critical Code Studies that looks at the code and culture of a 1-line program that ran on the Commodore 64. This book uses that 1-liner to explore BASIC programming culture in the 1980s and to reflect on its role in inspiring programmers to take the next step. By Nick Montfort, Patsy Baudoin, John Bell, Ian Bogost, Jeremy Douglass, Mark C. Marino, Michael Mateas, Casey Reas, Mark Sample and Noah Vawter

10 PRINT CHR$(205.5+RND(1)); : GOTO 10 (Thanks, Nick!)



  1. 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. 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. 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!

    1. 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. 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.

    1. 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;}’

      1. 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. 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. 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 ;_;

      1.  looking into it, thanks!  my heart isn’t in it like a youngster’s is, but that’s true of all things when you’re pushing 40.  I’ll dick around with it, though, for sure.

  7. 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!

  8. 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.

  9. 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.

  10. 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.

    1. in Commodore’s default Uppercase/Graphics character mode it prints symbols that are diagonal lines.

  11. 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.

  12. 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. 

    1. All numbers in Microsoft BASIC are stored as floats. CHR$ automatically rounds down. I just tested this:

      10 FOR I=1 TO 20:A=205.5+RND(1):PRINT A;CHR$(A);INT(A):NEXT I

    1.  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 :)

  13. 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!

Comments are closed.