Hacker News new | past | comments | ask | show | jobs | submit login
10 PRINT CHR$(205.5+RND(1)); : GOTO 10 (2012) (10print.org)
142 points by ghosthamlet 25 days ago | hide | past | web | favorite | 60 comments



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.


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


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


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




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.


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



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


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


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^^


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


You can recreate the magic in bash:

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


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

  ╱╲╱╲╱╲...╱╲╱╲╱╲╱╲
  ╲╱╲╲╲╲...╲╱╱╲╱╲╱╱
  ╱╲╲╲╱╱...╱╲╱╱╲╱╲╲
  ╲╱╲╲╱╲...╲╱╲╲╱╱╲╱
   :              :
   .              .
  ╱╱╲╲╱╲...╱╱╲╱╲╱╲╲
  ╲╲╱╲╲╱...╱╱╱╲╲╱╲╱
  ╱╱╱╲╲╱...╱╱╱╲╱╲╱╲
  ╲╱╲╱╲╱...╲╱╲╱╲╱╲╱


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

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


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


Doesn't quite work on my mac :/


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


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


The obligatory pure ASCII slash-backslash version:

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



Javascript version:

    for (let i=0;i<10000; i++) document.write(String.fromCharCode(9585 + Math.random()*2) + (i%100 == 99 ? '<br>':''))
    const  b = document.body.style;
    b['font-family'] = 'Courier New';
    b['font-size'] = b['line-height'] = '16px';
https://jsfiddle.net/qxjdtru6/

And a fun curvy variation:

https://jsfiddle.net/qxjdtru6/1/



This Maze Does Not Exist: an AI-powered labyrinth generator


I snickered at first but couldn't stop imagining ways to implement this. Thanks for giving me something to kickstart my brain today.



In 2013, I recreated the output as a shader in ShaderToy: https://www.shadertoy.com/view/ld23DW


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.


I also built something in JS inspired by 10print with some customisation https://jauny.github.io/10print/ :)


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


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


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


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.


My maze generator at http://tromp.github.io/pearls.html#maze produces arbitrarily long proper mazes on the fly. After compiling and running, enter -1 as the requested height.


For powershell:

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


A nice companion to https://nostarch.com/hemingway


That's a great read! The book inspired me to port that BASIC one-liner to Game Boy flavored assembly. Still having a Game Boy lying around? Now you have portable mazes:

https://github.com/svendahlstrand/10-print-game-boy


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


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



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


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


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?


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


I tried it in HP BASIC. (Played with a few terminal emulator settings and this is the best I got) https://imgur.com/a/N6QSkXB


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


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


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


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.


I see. RND returns a float.


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.


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


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


Lacks randomize()


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


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.


tl;dr: the output looks like this: https://ibb.co/Ypp9DZ3


Why does ibb need to know my location to serve an image?


It's requesting permission to send notifications, not your location. And it's because it loads https://cdn.siteswithcontent.com/js/push/subscribe.js?v=1.1.... whatever that's for. That domain is on various adblock lists.




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact

Search: