Features Podcasts Family Video Comics Music Tech Science Books Film & TV Games ✚

Jill

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

Cory Doctorow at 7:54 pm Mon, Nov 26, 2012

— FEATURED —

Science

Making sense of the confusing Supreme Court DNA patent ruling

Book Review

The 'Geisters: spooky, scary novel

Science

Ants and Stars: Bruce Sterling and Jasmina Tesanovic visit the Sardinia Radio Telescope in Italy

Feature

The Snowden Principle

— FOLLOW US —

Boing Boing is on Twitter and Facebook. Subscribe to our RSS feed or daily email.

 

— POLICIES —

Except where indicated, Boing Boing is licensed under a Creative Commons License permitting non-commercial sharing with attribution

 

— FONTS —

Tweet
Kindle


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

I write books. My latest is a YA science fiction novel called Homeland (it's the sequel to Little Brother). More books: Rapture of the Nerds (a novel, with Charlie Stross); With a Little Help (short stories); and The Great Big Beautiful Tomorrow (novella and nonfic). I speak all over the place and I tweet and tumble, too.

MORE:  books • computer science • happy mutants • Old school • scholarship

More at Boing Boing

Ants and Stars: Bruce Sterling and Jasmina Tesanovic visit the Sardinia Radio Telescope in Italy

The Snowden Principle

  • http://weirdly.net Jacob Ewing

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

  • semiotix

    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.

  • Nadreck

    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!

    • http://fallsastar.com Crashproof

      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.

  • Matisse Enzer

    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

      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: http://grumbel.blogspot.de/2011/04/c64-how-to-get-basic-programs-into.html

    • http://www.facebook.com/rsconto Richard Conto

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

      • http://www.facebook.com/rsconto Richard Conto

        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?

  • Ashley Yakeley

    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.

    • spacedoggy

       bah! – noob! ;)

  • http://twitter.com/amanicdroid Dr. Chronobiologist

    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: http://jsmachines.net/

    • SamSam

      D’oh, I guess it doesn’t have the right font… :(
      http://s3.amazonaws.com/awesome_screenshot/1108621?AWSAccessKeyId=0R7FMW7AXRVCYMAPTPR2&Expires=1354029490&Signature=8UzxwJLHf3giYiFC1BLvbRDBAaA%3D

  • noah django

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

    • http://twitter.com/amanicdroid Dr. Chronobiologist

      Hey man, you want to be good at computers? There’s still time. Macs have traditionally been good at getting the interface bullshit out of the way. Step 1 achieved: acquire computing device. Here’s step 2: https://www.coursera.org/course/cs101

      • noah django

         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.

  • http://www.rickcortes.com Rick.

    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!

  • MythicalMe

    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.

    • Tim Locke

      Microsoft also wrote the BASIC interpreters on the Commodore computers, including the Amiga.

  • http://twitter.com/youneedcoolin Johnny Coolin

    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.

    • Glen Able

      I assume the C64 used the usual linear congruential generator for generating pseudorandom numbers. 

      For reference, this is an example of what you get if you use “genuinely” random numbers (provided by random.org) 

      http://i50.tinypic.com/1zv30xf.jpg

  • Anders Candell

    Try it out here: 
    http://codeazur.com.br/stuff/fc64_final/

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

    • http://twitter.com/digitalArtform Joseph Francis

       I just tried it here
      http://www.calormen.com/applesoft/

  • Cameron McCormick

    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.

    • http://twitter.com/amanicdroid Dr. Chronobiologist

      Most of the buyers will be academic libraries.

    • dougsurlee

       perhaps if you used your non-dead tree mind you might have found that it is available as an e-book: http://mitpress-ebooks.mit.edu/product/10-print-chr2055rnd1-goto

    • nmdjohn

       Actually, the whole thing is available as a Creative Commons licensed PDF on the book’s site:  http://10print.org/

  • hbgvfcdxsz hbgvfcdxsz

    what does the program do? print NMNMNMNMN?

    • Glippiglop

      It’s a random sequence of forward slashes and back slashes.

    • Larry Anderson

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

  • http://synerdata.net/ Gordon Stark

    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.

  • Quibbler

    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. 

    • Tim Locke

      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

    • http://twitter.com/kpkpkp Kevin Pierce

      : Separates statements typed on the same line.

  • http://twitter.com/tadasyoyolt Tadas Jelinek

    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:
    http://www.youtube.com/watch?v=7lcQ-HDepqk

    • http://twitter.com/beep54orama B E Pratt

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

  • Doug in_PDX

    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!