skrebbel 7 years ago

It bothers me way more than it should that this line of code has become known as "10print". Like, 95% of BASIC oneliners out there start with "10 PRINT". It's like calling a McDonald's Super Size Big Tasty Meal With Diet Coke And A Side Salad a "Mac".

It should've been called 205.5+RND or something. Grmbl.

  • bdowling 7 years ago

    It’s like using “Dear” to refer to some particular famous letter.

    • skrebbel 7 years ago

      That's the analogy I was looking for. Thanks!

  • kazinator 7 years ago

    The visual effect it produces is not even portable, even it is tied to a machine's 8 bit extensions to 7 bit ASCII.

th0ma5 7 years ago
  • cryptonector 7 years ago

    Yes, I see now, you could use that as the start of a book.

  • bartread 7 years ago

    Gordon Bennett! That certainly provides a stark reminder of how slow BASIC was on the Commodore 64.

    This rings a bell though: I remember encountering it back when I owned the machine, possibly in the BASIC manual that came with it, possibly in a magazine, or perhaps somebody at school mentioned it.

snek 7 years ago
  • shrimpx 7 years ago

    Should fix the line height so the lines connect to each other.

    • snek 7 years ago

      which browser doesn't show that right? chrome and firefox have connected lines for me

      • bananicorn 7 years ago

        Firefox doesn't - but it probably falls back on system fonts for me - there the line height needs to be at around 1.15em...

        Not that that helps in any way, since you never know which font might be used^^

      • omaranto 7 years ago

        The lines are not connected here, on Chrome. Maybe it depends on what fonts you have installed?

caf 7 years ago

You can recreate the magic in bash:

  while true; do printf "\u$((2571 + ($RANDOM & 1)))"; done
  • timClicks 7 years ago

    It's a shame that our fonts don't have the same aspect ratio. But that's a neat trick.

  • Nursie 7 years ago

    Doesn't quite work on my mac :/

    • mojuba 7 years ago

      Got it! This works on macOS. It encodes the same characters in hex UTF-8:

         while true; do printf "\xe2\x95\xb$((1 + ($RANDOM & 1)))"; done
      • Nursie 7 years ago

        Excellent work! Thankyou, that's awesome and very fast....

    • kazinator 7 years ago

      The obligatory pure ASCII slash-backslash version:

        while true; do printf $(printf "\\\\u%04x" $((47 + 45 * ($RANDOM % 2)))); done
  • fooblat 7 years ago

    And for an even more "authentic" old school experience in bash:

    while true; do printf "\u$((2571 + ($RANDOM & 1)))"; sleep 0.02; done

  • kazinator 7 years ago

    Fun task: write a program which takes such output, identifies all enclosed cells, and breaks them open, so that the maze is connected: any two points in the maze are connected by at least one path.

    Bonus: close loops, so any two places in the maze are connected by a unique path.

    As a preprocessing step, reformat the data to 77-column-long lines first, removing any whitespace characters, and discarding the last line if it is shorter than 79 characters, and then close off the exterior with solid zig-zags, like this, which are strictly added to the data (no overwriting):

      ╱╲╱╲╱╲...╱╲╱╲╱╲╱╲
      ╲╱╲╲╲╲...╲╱╱╲╱╲╱╱
      ╱╲╲╲╱╱...╱╲╱╱╲╱╲╲
      ╲╱╲╲╱╲...╲╱╲╲╱╱╲╱
       :              :
       .              .
      ╱╱╲╲╱╲...╱╱╲╱╲╱╲╲
      ╲╲╱╲╲╱...╱╱╱╲╲╱╲╱
      ╱╱╱╲╲╱...╱╱╱╲╱╲╱╲
      ╲╱╲╱╲╱...╲╱╲╱╲╱╲╱
AndrewKemendo 7 years ago

For powershell:

for(){Write-Host(Random("\","/"))-N}

jquinby 7 years ago

Nice. This brings back some great memories. I used to do a similar one-liner that alternated between white and black blocks, which created crossword-puzzle-like patterns. I'd sit across the room and squint at the display, hoping to see some sort of emergent pattern.

zestyping 7 years ago

Alas! I was hoping the pattern would change every time I refreshed the page.

rkagerer 7 years ago

Love it! Brings up so much nostalgia from the days of programming on my old TRS-80. But is it really a maze? Once you start, you don't seem to get much choice of path...

  • Kurtz79 7 years ago

    Of course not, there is no logic behind it, save for printing "walls" that line up with each other.

    It's a (neat) graphic trick.

  • Starwatcher2001 7 years ago

    You might enjoy this game written in a single line of BASIC on a TRS-80:

    https://www.youtube.com/watch?v=lWyZO-yPnvM

    For anyone not familiar with the TRS-80, who finds the code somewhat weird.. the BASIC implementation was written by Microsoft. Only the first two letters of variable names were significant. Although interpreted, the ROM tokenized typed lines, meaning it didn't care about spaces.

    This led to such gems as:

    FORK=10 TOMATOES STEP LADDER

mycall 7 years ago

This was my favorite thing to do on TSR-80s at Radio Shack, then walk away, although I would do all characters instead.

pantulis 7 years ago

In the same book, an old one-liner called "BURROW" from Pet Gazette:

1A$="[up][down][left][right]":PRINTMID$(A$,RND(.5)4+1,1)"[left]";:FORI=1TO30:NEXT:PRINT"[rvson][space][left]";:GOTO1

golergka 7 years ago

A bit disappointed that this page doesn't generate the maze with each visit

kazinator 7 years ago

This is poorly documented; I don't see a REM statement.

SeanLuke 7 years ago

Why the 205.5? Why wouldn't this work as 205 + RND(1)?

  • scbrg 7 years ago

    RND(1) returns a value between 0 and 1, but always lower than 1. Thus, the result of 205+RND(1) will always be 205 point something, which in turn will be truncated to 205. Thus, it will always result in the same character.

    • SeanLuke 7 years ago

      I see. RND returns a float.

      • soneil 7 years ago

        It's more that the decimal is always rounded down. So you don't want a value between 205 and 205.9999999, as it'll always be rounded down to 205. you want a value between 205.5 and 206.49999999, so when rounded down it has a (practically) even chance of landing on either 205 or 206.

  • Voltage 7 years ago

    In CBM BASIC RND(1) returned a floating point value between 0.0 (inclusive) and 1.0 (exclusive).

    205 + RND(1) would always evaluate to 205 when truncated.

    205.5 + RND(1) pseudo randomly selects between 205 and 206

fnord77 7 years ago

this book reads like an article on a modern art piece.

jesuslop 7 years ago

Lacks randomize()

  • DanBC 7 years ago

    I think Commodore BASIC had a more complex way of seeding the random timer: https://www.c64-wiki.com/wiki/RND

        POKE 56328,0    : REM real-time clock activate with 1/10s -> clock runs ($DC08)
        PRINT RND(0)    : REM Random number addicted by timer and real-time clock
    • Voltage 7 years ago

      You could also do I=RND(-TI)

      Providing a neg number to RND would "reseed" the random number generator. TI was a "system" variable that updates every 60th of a second.

neatcoder 7 years ago

Is there anyone here who still writes code in BASIC? If so which interpreter/compiler do you use?

  • gushie 7 years ago

    I do so professionally. Our 35+ year old application is written in what was once VAX BASIC running on OpenVMS (Now on Integrity and called HP BASIC).

    • neatcoder 7 years ago

      Wow! Can you share your story more? What does your application do? Why did you choose BASIC 35 years ago? Did the question about rewriting it another language come up anytime? How did such discussions go? Do you enjoy writing BASIC code?

      • gushie 7 years ago

        I've been with the company 20 years so wasn't involved in the original decision. I believe the company started out on PDP's before moving to MicroVAX (and later Alpha and Integrity). BASIC will likely have been the best fit at the time. It is business software for the Agri industry, originally a terminal text entry system. Now we also have a web front end (running on Windows IIS, communicating to VMS/BASIC via Apache Tomcat/WSIT webservices). We did try converting to VB6 back when it was a thing, but then .NET happened so we abandoned it as conversion to VB.NET wasn't so straight forward. A rewrite in C# was briefly considered before finally going for the web front end/web services option to avoid rewriting the BASIC business/data layer. Sadly the application will go end of life in a couple of years, as we're now part of a larger corporation who have similar applications. Ours lost out due to the OpenVMS layer being a hard sell to new customers. I've never really thought about when I enjoy it! It's mostly a data entry / reporting application, so generally not very exciting :)