Hacker News new | comments | show | ask | jobs | submit login

A version that works in bash:

yes 'c=(╱ ╲);printf ${c[RANDOM%2]}'|bash

Source and credit: http://stackoverflow.com/a/13612327

Beautiful: http://i.imgur.com/tsFR9.png

I can't believe I've programmed for 15 years without knowing about this.

PowerShell for those on Windows:

for (;;) { write-host -n (get-random ╱,╲) }

Obviously this requires a font supporting those characters. MS Mincho seems to serve well: http://www.microsoft.com/typography/fonts/font.aspx?FMID=206

If you don't want to install a font, you can use slashes. Works pretty well.

    for (;;) { write-host -n (get-random /,\) }
It's kind of nice with _ and | too :

    for (;;) { write-host -n (get-random '_','|') }

You can also just use for(){...}. No need for the semicolons there.

After reading the article, I was really hoping the comments would be full of ports, glad to see this thread! Here's a version for the Inferno shell, because I couldn't resist:

wm/sh -c 'load std mpexpr;while{}{unicode -t ${expr 2571 1 rand +}}'

The one-line shell command python version ended up being surprisingly painful:

    echo "# -*- coding: utf-8 -*-\\nfrom random import choice\\nwhile(True):\\n  print(choice(\"╱╲\"), end='')" | python3

    python3 -c 'exec("from random import choice\nwhile(True):\n  print(choice(\"╱╲\"), end='"''"')")'
(Oh, the fun of deeply nested quote escaping!)

The exec/echo thing being required since we need multiple lines, because while ';' is the statement separator python barfs on "import foo; while (True): pass". Bug or spec?

I did it with

    python3 -c "`echo -e 'import time\nwhile True:\n print(u"\u2571\u2572"[int(time.time() * 100)%2],end="")\n time.sleep(0.001)'`"
The neat thing about it is that the randomness comes from the inexactness of time.sleep

You can write it like this:

    python -c "while 1:import sys,random;sys.stdout.write(random.choice('\/'))"
and it's shorter too !

It is a spec. Python in general prefers a statement over an expression, so the while statement does not have an expression form.

Python has two types of statements; "simple" statement and "compound" statements. Compound statements are those, like the if- and while-statements, which require multiple lines.

Only simple statements may be separated by a ';', not compound statements.

This is a bit different than what you wrote. For example, "x=4" is a statement, and not an expression, but "x=4;y=5;z=6" is a valid Python line because assignment is a simple statement, and multiple simple statements may be separated by a ';'.


echo 'loop do print ["\u2571","\u2572"].sample end'|ruby

This makes it slower, so it's more pleasant to watch:

echo 'loop do print ["\u2571","\u2572"].sample ; sleep 0.001 end'|ruby

Why piping to ruby? You have the -e operator for that:

    ruby -e 'loop do print ["\u2571","\u2572"].sample ; sleep 0.001 end'

I can't resist a golf!

    ruby -e 'print %W{\u2571 \u2572}.sample while sleep 1e-3'
(Updated: Made 3 chars shorter.)

And a shorter, but cheats, version:

    yes|ruby -pe'$_=%W{\u2571 \u2572}.sample;sleep 1e-3'
My favorite overall balance of readability and shortness though is:

    ruby -e 'print %w{╱ ╲}.sample while sleep 0.01'

Amazing! I always forget about the `something while other_thing` syntax, thank you for reminding me of it :)

I tried to like it. I bumped up the font size to 36 points. I slowed down the loop to .01 seconds. Unfortunately, it isn't remotely the same.

The C64 had magic. I miss my old C64.

Try this: http://www.secretgeometry.com/apps/cathode/

Lots of fun. Use it to make old stuff like this feel more authentic, or just run your builds in it and tell your housemates you're haxxing teh gibson.

TBH though the reason it doesn't feel the same is ultimately because you're not the person you were 20-30 years ago, whoever that was. Nothing to do with the code or its execution environment.

While it was far better (and thanks for the pointer to Cathode!), I figured out what the problems are. First (and probably most important), the lines being output don't touch each other, so there are horizontal gaps across the entire screen. Second, the glyphs are much thinner, reducing the feeling of "wall".

What a totally clever app. And extremely well done. Thanks for sharing! Brought joy to this not-so-old-but-old-enough child of the 80s :)

A slight modification to make it generate mostly solvable mazes: `yes 'c=(┻ ┫);printf ${c[RANDOM%2]}'|bash`

choosing from

  || __     # (2 pipes, one space, 2 bars)
seems to work pretty well, too

Perl 6, using Rakudo:

perl6 -e 'loop { print <9585 9586>.roll.chr }'

In fact, perl6 -e 'loop { print <╱ ╲>.roll }' will work too if your terminal is set up properly.

Interactive JavaScript version: http://js.do/samples/labyrinth

Hmm.. thats not a oneliner. Which is what makes the Basic version interesting in the first place. Also it differs in that it does not run continously.

I shortened it a bit:


Still not as elegant as the Basic version.

This is one of the big downsides of how javascript is implemented in the browsers these days. There is no simple way to redraw the screen. You have to turn your whole program into a state machine and work with timouts just to display something.

> ...not as elegant as the BASIC version

Beautiful statement. So much unintentional irony, and at the same time so very true in this context.

I won't claim this is elegant, but here's the same thing in one line:

for(i=1;i<300;i++) document.write(i % 30 == 0 ? "<br>" : (Math.random()>0.5) ? '\u2571' : '\u2572');

(function draw(i){ return function () { document.write(i%30==0 ? '<br>' : Math.random()>0.5?'\u2571':'\u2572'); setTimeout(draw(i+1), 100) } }(1)())

A throttled run-forever version.

edit, slightly neater:

(function draw(i){ setTimeout(function (){ document.write(i%30==0 ? '<br>' : Math.random()>0.5 ? '\u2571':'\u2572'); draw(i+1); }, 100) }(1))

Here's a JavaScript version without the linebreaks (it uses zero-width spaces instead): http://tinkerbin.com/uEvgxZ6g

JS: for(i=0;i<1000;i++) document.write(['\u2571\u200B', '\u2572\u200B'][(Math.floor((Math.random()*2)))])

CSS: body {line-height: 1}

Watch it character-by-character in bash:

while true; do c=(╱ ╲);printf ${c[RANDOM%2]}; sleep .0001; done

Not for me. "syntax error near unexpected token ';' == no printf

It worked for me when I copied it, not when I tried retyping it. I think the fancy unicode ╱ ╲ matters vs. plain ascii \/

ascii works for me if I escape the \, ie: / \\

Was it maybe trouble with '\' being treated as an escape character?

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